InaccessibleMenuLink.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\Core\Menu;
  3. use Drupal\Component\Plugin\Exception\PluginException;
  4. /**
  5. * A menu link plugin for wrapping another menu link, in sensitive situations.
  6. *
  7. * @see \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::checkAccess()
  8. */
  9. class InaccessibleMenuLink extends MenuLinkBase {
  10. /**
  11. * The wrapped menu link.
  12. *
  13. * @var \Drupal\Core\Menu\MenuLinkInterface
  14. */
  15. protected $wrappedLink;
  16. /**
  17. * Constructs a new InaccessibleMenuLink.
  18. *
  19. * @param \Drupal\Core\Menu\MenuLinkInterface $wrapped_link
  20. * The menu link to wrap.
  21. */
  22. public function __construct(MenuLinkInterface $wrapped_link) {
  23. $this->wrappedLink = $wrapped_link;
  24. $plugin_definition = [
  25. 'route_name' => '<front>',
  26. 'route_parameters' => [],
  27. 'url' => NULL,
  28. ] + $this->wrappedLink->getPluginDefinition();
  29. parent::__construct([], $this->wrappedLink->getPluginId(), $plugin_definition);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getTitle() {
  35. return $this->t('Inaccessible');
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function getDescription() {
  41. return '';
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getCacheContexts() {
  47. return $this->wrappedLink->getCacheContexts();
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getCacheTags() {
  53. return $this->wrappedLink->getCacheTags();
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getCacheMaxAge() {
  59. return $this->wrappedLink->getCacheMaxAge();
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function updateLink(array $new_definition_values, $persist) {
  65. throw new PluginException('Inaccessible menu link plugins do not support updating');
  66. }
  67. }