Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / menu_ui / menu_ui.module
index cffccde76801fc70a96a3ce16f4d546cec0a80ff..cb1e85307f5cda7d31388c211d5407fca85c3428 100644 (file)
@@ -10,7 +10,6 @@
 
 use Drupal\Core\Breadcrumb\Breadcrumb;
 use Drupal\Core\Cache\CacheableMetadata;
-use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Block\BlockPluginInterface;
 use Drupal\Core\Link;
 use Drupal\Core\Menu\MenuLinkInterface;
@@ -27,6 +26,8 @@ use Drupal\node\NodeInterface;
  * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
  *   \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH because the
  *   menu name is a configuration entity ID.
+ *
+ * @see https://www.drupal.org/node/2831620
  */
 const MENU_MAX_MENU_NAME_LENGTH_UI = 27;
 
@@ -71,6 +72,10 @@ function menu_ui_entity_type_build(array &$entity_types) {
     ->setLinkTemplate('edit-form', '/admin/structure/menu/manage/{menu}')
     ->setLinkTemplate('add-link-form', '/admin/structure/menu/manage/{menu}/add')
     ->setLinkTemplate('collection', '/admin/structure/menu');
+
+  if (isset($entity_types['node'])) {
+    $entity_types['node']->addConstraint('MenuSettings', []);
+  }
 }
 
 /**
@@ -166,24 +171,6 @@ function _menu_ui_node_save(NodeInterface $node, array $values) {
   $entity->save();
 }
 
-/**
- * Implements hook_ENTITY_TYPE_predelete() for node entities.
- */
-function menu_ui_node_predelete(EntityInterface $node) {
-  // Delete all MenuLinkContent links that point to this node.
-  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
-  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
-  $result = $menu_link_manager->loadLinksByRoute('entity.node.canonical', ['node' => $node->id()]);
-
-  if (!empty($result)) {
-    foreach ($result as $id => $instance) {
-      if ($instance->isDeletable() && strpos($id, 'menu_link_content:') === 0) {
-        $instance->deleteLink();
-      }
-    }
-  }
-}
-
 /**
  * Returns the definition for a menu link for the given node.
  *
@@ -357,6 +344,15 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
       $form['actions'][$action]['#submit'][] = 'menu_ui_form_node_form_submit';
     }
   }
+
+  $form['#entity_builders'][] = 'menu_ui_node_builder';
+}
+
+/**
+ * Entity form builder to add the menu information to the node.
+ */
+function menu_ui_node_builder($entity_type, NodeInterface $entity, &$form, FormStateInterface $form_state) {
+  $entity->menu = $form_state->getValue('menu');
 }
 
 /**