Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / src / Entity / Menu.php
index e7fbb47fbfc92cf7793e596c1d8a9c120b3e1ffa..14830099e0a2562f5f55408e0d04f8de9b07c456 100644 (file)
@@ -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();
+    }
+  }
+
 }