comparison 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
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\system\Entity; 3 namespace Drupal\system\Entity;
4 4
5 use Drupal\Core\Config\Entity\ConfigEntityBase; 5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\system\MenuInterface; 7 use Drupal\system\MenuInterface;
7 8
8 /** 9 /**
9 * Defines the Menu configuration entity class. 10 * Defines the Menu configuration entity class.
10 * 11 *
11 * @ConfigEntityType( 12 * @ConfigEntityType(
12 * id = "menu", 13 * id = "menu",
13 * label = @Translation("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 * ),
14 * handlers = { 22 * handlers = {
15 * "access" = "Drupal\system\MenuAccessControlHandler" 23 * "access" = "Drupal\system\MenuAccessControlHandler"
16 * }, 24 * },
17 * admin_permission = "administer menu", 25 * admin_permission = "administer menu",
18 * entity_keys = { 26 * entity_keys = {
69 */ 77 */
70 public function isLocked() { 78 public function isLocked() {
71 return (bool) $this->locked; 79 return (bool) $this->locked;
72 } 80 }
73 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
74 } 121 }