I have another view that uses the same path as the front page view which is "/node" and I will like to disable the front page view programmatically.
How can I do that from a hook_install?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Views are entities, so:
Load the View:
$view_id = 'content'; // Replace with the ID of the view you wish to disable. $view = \Drupal::entityTypeManager()->getStorage('view')->load($view_id);
Update the status:
And save it:
Or all in one go:
\Drupal::entityTypeManager()->getStorage('view') ->load($view_id) ->setStatus(FALSE) ->save();
Even simpler - with the only real drawbacks being that you need a use statement for
View and it assumes that is the class for view objects, which would be very unusual not to be the case: