This question is related to two issues on drupal.org:
- Standard profile: make "Home" menu link to editable/deletable
- Orphaned menu items should support removeDefinition
How to delete a menu item that was defined in
example.links.menu.yml and then changed, for example by disabling it or changing its weight.
Steps to reproduce
- Install a clean Drupal 8 with the Standard installation profile
- Go to
admin/structure/menu/manage/mainand disable the
Homemenu item. This change will write the menu item to
- Delete file
- Clear cache
Try to delete the now orphaned menu item:
$home_manager = \Drupal::service('plugin.manager.menu.link'); $home_manager->removeDefinition('standard.front_page');
We are able to delete the menu item.
We get the following error:
Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginException: "Menu link plugin with ID 'standard.front_page' does not support deletion".
Is this a bug in Drupal core, or am I using the wrong way to delete the menu item?