3 namespace Drupal\system\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\system\MenuInterface;
10 * Defines the Menu configuration entity class.
14 * label = @Translation("Menu"),
15 * label_collection = @Translation("Menus"),
16 * label_singular = @Translation("menu"),
17 * label_plural = @Translation("menus"),
18 * label_count = @PluralTranslation(
19 * singular = "@count menu",
20 * plural = "@count menus",
23 * "access" = "Drupal\system\MenuAccessControlHandler"
25 * admin_permission = "administer menu",
38 class Menu extends ConfigEntityBase implements MenuInterface {
41 * The menu machine name.
48 * The human-readable name of the menu entity.
55 * The menu description.
59 protected $description;
62 * The locked status of this menu.
66 protected $locked = FALSE;
71 public function getDescription() {
72 return $this->description;
78 public function isLocked() {
79 return (bool) $this->locked;
85 public static function preDelete(EntityStorageInterface $storage, array $entities) {
86 parent::preDelete($storage, $entities);
87 /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
88 $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
89 foreach ($entities as $menu) {
90 // Delete all links from the menu.
91 $menu_link_manager->deleteLinksInMenu($menu->id());
98 public function save() {
99 $return = parent::save();
100 \Drupal::cache('menu')->invalidateAll();
101 // Invalidate the block cache to update menu-based derivatives.
102 if (\Drupal::moduleHandler()->moduleExists('block')) {
103 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
111 public function delete() {
113 \Drupal::cache('menu')->invalidateAll();
115 // Invalidate the block cache to update menu-based derivatives.
116 if (\Drupal::moduleHandler()->moduleExists('block')) {
117 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();