X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FEntity%2FMenu.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FEntity%2FMenu.php;h=14830099e0a2562f5f55408e0d04f8de9b07c456;hp=e7fbb47fbfc92cf7793e596c1d8a9c120b3e1ffa;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/system/src/Entity/Menu.php b/web/core/modules/system/src/Entity/Menu.php index e7fbb47fb..14830099e 100644 --- a/web/core/modules/system/src/Entity/Menu.php +++ b/web/core/modules/system/src/Entity/Menu.php @@ -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 @@ use Drupal\system\MenuInterface; * @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 @@ class Menu extends ConfigEntityBase implements MenuInterface { 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(); + } + } + }