diff --git a/src/MasqueradeMenuLinkTree.php b/src/MasqueradeMenuLinkTree.php new file mode 100644 index 0000000..100d79b --- /dev/null +++ b/src/MasqueradeMenuLinkTree.php @@ -0,0 +1,31 @@ + $item) { + if (strstr($item->link->getRouteName(), 'masquerade.unmasquerade')) { + $masquerade = \Drupal::service('masquerade'); + if (!$masquerade->isMasquerading()) { + unset($tree[$index]); + } + } + } + return $tree; + } + +} diff --git a/src/MasqueradeServiceProvider.php b/src/MasqueradeServiceProvider.php new file mode 100644 index 0000000..f19873d --- /dev/null +++ b/src/MasqueradeServiceProvider.php @@ -0,0 +1,21 @@ +getDefinition('menu.link_tree'); + $definition->setClass(MasqueradeMenuLinkTree::class); + } + +} diff --git a/src/ProxyClass/MasqueradeMenuLinkTree.php b/src/ProxyClass/MasqueradeMenuLinkTree.php new file mode 100644 index 0000000..d120b61 --- /dev/null +++ b/src/ProxyClass/MasqueradeMenuLinkTree.php @@ -0,0 +1,118 @@ +container = $container; + $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id; + } + + /** + * {@inheritdoc} + */ + public function getCurrentRouteMenuTreeParameters($menu_name) { + return $this->lazyLoadItself()->getCurrentRouteMenuTreeParameters($menu_name); + } + + /** + * Lazy loads the real service from the container. + * + * @return object + * Returns the constructed real service. + */ + protected function lazyLoadItself() { + if (!isset($this->service)) { + $this->service = $this->container->get($this->drupalProxyOriginalServiceId); + } + + return $this->service; + } + + /** + * {@inheritdoc} + */ + public function load($menu_name, MenuTreeParameters $parameters) { + return $this->lazyLoadItself()->load($menu_name, $parameters); + } + + /** + * {@inheritdoc} + */ + public function transform(array $tree, array $manipulators) { + return $this->lazyLoadItself()->transform($tree, $manipulators); + } + + /** + * {@inheritdoc} + */ + public function build(array $tree) { + return $this->lazyLoadItself()->build($tree); + } + + /** + * {@inheritdoc} + */ + public function maxDepth() { + return $this->lazyLoadItself()->maxDepth(); + } + + /** + * {@inheritdoc} + */ + public function getSubtreeHeight($id) { + return $this->lazyLoadItself()->getSubtreeHeight($id); + } + + /** + * {@inheritdoc} + */ + public function getExpanded($menu_name, array $parents) { + return $this->lazyLoadItself()->getExpanded($menu_name, $parents); + } + + } + +}