-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch menu position rule module for orphaned items
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |