I have a custom form on my site, and on submission, I'd like to update a Views page path.

Within my module, I have a form alter which eventually attaches a custom submit function where I plan to run this Views path change. Within my submit function, so far I have:

function _my_module_custom_submit() {
    $view = \Drupal\views\Views::getView('custom_view');
    // TODO: Change Views path

    // Save View

This function is running fine, however I cannot find how to change the Views Display path at all. I've tried the setHandler() and setHandlerOption() methods, but these don't appear to be working for this case.

I've found plenty of examples to change the Views path programatically in Drupal 7, but have yet to come across an example for Drupal 8.


In Drupal 8 the configuration of a View is stored in an entity, which you can load, modify and save:

use Drupal\views\Entity\View;

  $view = View::load('custom_view');
  $display =& $view->getDisplay('page_1');
  $display['display_options']['path'] = 'example/path';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.