X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmenu_ui%2Fmenu_ui.module;fp=web%2Fcore%2Fmodules%2Fmenu_ui%2Fmenu_ui.module;h=cb1e85307f5cda7d31388c211d5407fca85c3428;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=cffccde76801fc70a96a3ce16f4d546cec0a80ff;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/menu_ui/menu_ui.module b/web/core/modules/menu_ui/menu_ui.module index cffccde76..cb1e85307 100644 --- a/web/core/modules/menu_ui/menu_ui.module +++ b/web/core/modules/menu_ui/menu_ui.module @@ -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'); } /**