Skip to content

Commit

Permalink
Patch menu position rule module for orphaned items
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed May 19, 2022
1 parent 38f925c commit 4c258b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions patches/contrib/menu_postion_rule-edit_route.patch
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 4c258b1

Please sign in to comment.