Mercurial > hg > isophonics-drupal-site
diff core/modules/system/src/Entity/Menu.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/modules/system/src/Entity/Menu.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/modules/system/src/Entity/Menu.php Thu Feb 28 13:21:36 2019 +0000 @@ -3,6 +3,7 @@ namespace Drupal\system\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\system\MenuInterface; /** @@ -11,6 +12,13 @@ * @ConfigEntityType( * id = "menu", * label = @Translation("Menu"), + * label_collection = @Translation("Menus"), + * label_singular = @Translation("menu"), + * label_plural = @Translation("menus"), + * label_count = @PluralTranslation( + * singular = "@count menu", + * plural = "@count menus", + * ), * handlers = { * "access" = "Drupal\system\MenuAccessControlHandler" * }, @@ -71,4 +79,43 @@ return (bool) $this->locked; } + /** + * {@inheritdoc} + */ + public static function preDelete(EntityStorageInterface $storage, array $entities) { + parent::preDelete($storage, $entities); + /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ + $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); + foreach ($entities as $menu) { + // Delete all links from the menu. + $menu_link_manager->deleteLinksInMenu($menu->id()); + } + } + + /** + * {@inheritdoc} + */ + public function save() { + $return = parent::save(); + \Drupal::cache('menu')->invalidateAll(); + // Invalidate the block cache to update menu-based derivatives. + if (\Drupal::moduleHandler()->moduleExists('block')) { + \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); + } + return $return; + } + + /** + * {@inheritdoc} + */ + public function delete() { + parent::delete(); + \Drupal::cache('menu')->invalidateAll(); + + // Invalidate the block cache to update menu-based derivatives. + if (\Drupal::moduleHandler()->moduleExists('block')) { + \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); + } + } + }