From 4c258b1f90114dfe2c1bbfce9a146abd1f7c189d Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 19 May 2022 14:30:55 -0700 Subject: [PATCH] Patch menu position rule module for orphaned items --- composer.json | 3 +- .../menu_postion_rule-edit_route.patch | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 patches/contrib/menu_postion_rule-edit_route.patch diff --git a/composer.json b/composer.json index 6c18fb731f..f4d8595606 100644 --- a/composer.json +++ b/composer.json @@ -334,7 +334,8 @@ "https://www.drupal.org/project/menu_link_weight/issues/2995896": "https://www.drupal.org/files/issues/2018-08-29/2995896-menu-admin-per-menu-support-fixes.patch" }, "drupal/menu_position": { - "https://www.drupal.org/project/menu_position/issues/3110502": "https://www.drupal.org/files/issues/2020-07-29/drupal-menu_position-WSOD-when-menu-parent-no-longer-exists-3110502-26.patch" + "https://www.drupal.org/project/menu_position/issues/3110502": "https://www.drupal.org/files/issues/2020-07-29/drupal-menu_position-WSOD-when-menu-parent-no-longer-exists-3110502-26.patch", + "Clean menu tree": "patches/contrib/menu_postion_rule-edit_route.patch" }, "drupal/paragraphs": { "https://www.drupal.org/project/paragraphs/issues/2895561": "https://www.drupal.org/files/issues/2021-05-06/paragraphs-2895561-32.patch" diff --git a/patches/contrib/menu_postion_rule-edit_route.patch b/patches/contrib/menu_postion_rule-edit_route.patch new file mode 100644 index 0000000000..6e477b1ab3 --- /dev/null +++ b/patches/contrib/menu_postion_rule-edit_route.patch @@ -0,0 +1,29 @@ +diff --git a/src/Plugin/Menu/MenuPositionLink.php b/src/Plugin/Menu/MenuPositionLink.php +index 0724d3a..cd22a83 100644 +--- a/src/Plugin/Menu/MenuPositionLink.php ++++ b/src/Plugin/Menu/MenuPositionLink.php +@@ -6,6 +6,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; + use Drupal\Core\Controller\TitleResolverInterface; + use Drupal\Core\Entity\EntityTypeManagerInterface; + use Drupal\Core\Menu\MenuLinkBase; ++use Drupal\Core\Menu\MenuTreeStorage; + use Drupal\Core\Plugin\ContainerFactoryPluginInterface; + use Drupal\Core\Render\RendererInterface; + use Drupal\Core\Routing\AdminContext; +@@ -214,8 +215,14 @@ class MenuPositionLink extends MenuLinkBase implements ContainerFactoryPluginInt + public function getEditRoute() { + $storage = $this->entityTypeManager->getStorage('menu_position_rule'); + $entity_id = $this->pluginDefinition['metadata']['entity_id']; +- $entity = $storage->load($entity_id); +- return $entity->toUrl(); ++ if ($entity = $storage->load($entity_id)) { ++ return $entity->toUrl(); ++ } ++ \Drupal::service('menu.tree_storage') ++ ->delete($this->pluginDefinition['id']); ++ $this->messenger() ++ ->addError($this->t('Unable to load menu position rule %entity_id. It has been deleted from the menu tree.', ['%entity_id' => $entity_id])); ++ return NULL; + } + + }