I am trying to programmatically delete an existing view’s display (at the same time as deleting a node) but I am not able to find the good implementation.

HOOK_node_delete(Drupal\Core\Entity\EntityInterface $node) {
$view = Views::getView("VIEW_MACHINE_NAME");
$display_name = "block_1";
$views_display = $view->storage->getDisplay($display_name);

I can access to the view’s display using the view entity (storage) but as the display has protected access I can’t delete it.

Any help?

1 Answer 1


DisplayPluginCollection has a remove() method:


But this doesn't work and I couldn't find any code which is trying to actually remove the display from configuration.

So you would have to do this yourself in the view entity (storage):

$view = \Drupal\views\Views::getView('myview');
$storage = $view->storage;
$displays = $storage->get('display');
$storage->set('display', $displays);

The problem is this will not run the remove code of the display. For a block display this doesn't matter, but if you delete a page display you might consider running the remove method mentioned above before deleting the display from storage. This will delete the menu links from the page.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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