Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / src / Entity / Menu.php
1 <?php
2
3 namespace Drupal\system\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\system\MenuInterface;
8
9 /**
10  * Defines the Menu configuration entity class.
11  *
12  * @ConfigEntityType(
13  *   id = "menu",
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",
21  *   ),
22  *   handlers = {
23  *     "access" = "Drupal\system\MenuAccessControlHandler"
24  *   },
25  *   admin_permission = "administer menu",
26  *   entity_keys = {
27  *     "id" = "id",
28  *     "label" = "label"
29  *   },
30  *   config_export = {
31  *     "id",
32  *     "label",
33  *     "description",
34  *     "locked",
35  *   }
36  * )
37  */
38 class Menu extends ConfigEntityBase implements MenuInterface {
39
40   /**
41    * The menu machine name.
42    *
43    * @var string
44    */
45   protected $id;
46
47   /**
48    * The human-readable name of the menu entity.
49    *
50    * @var string
51    */
52   protected $label;
53
54   /**
55    * The menu description.
56    *
57    * @var string
58    */
59   protected $description;
60
61   /**
62    * The locked status of this menu.
63    *
64    * @var bool
65    */
66   protected $locked = FALSE;
67
68   /**
69    * {@inheritdoc}
70    */
71   public function getDescription() {
72     return $this->description;
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function isLocked() {
79     return (bool) $this->locked;
80   }
81
82   /**
83    * {@inheritdoc}
84    */
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());
92     }
93   }
94
95   /**
96    * {@inheritdoc}
97    */
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();
104     }
105     return $return;
106   }
107
108   /**
109    * {@inheritdoc}
110    */
111   public function delete() {
112     parent::delete();
113     \Drupal::cache('menu')->invalidateAll();
114
115     // Invalidate the block cache to update menu-based derivatives.
116     if (\Drupal::moduleHandler()->moduleExists('block')) {
117       \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
118     }
119   }
120
121 }