Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. namespace DrupalYOUR_MODULEPluginDerivative;
  4.  
  5. use DrupalComponentPluginDerivativeDeriverBase;
  6. use DrupalCorePluginDiscoveryContainerDeriverInterface;
  7. use DrupalCoreEntityEntityStorageInterface;
  8. use SymfonyComponentDependencyInjectionContainerInterface;
  9.  
  10.  
  11. /**
  12. * Provides menu links.
  13. */
  14. class MyLinks extends DeriverBase implements ContainerDeriverInterface {
  15.  
  16. /**
  17. * The team storage.
  18. *
  19. * @var DrupalCoreEntityEntityStorageInterface
  20. */
  21. protected $myStorage;
  22.  
  23.  
  24. /**
  25. * Constructs a XX instance.
  26. *
  27. * @param DrupalCoreEntityEntityStorageInterface $storage
  28. * The storage.
  29. */
  30. public function __construct(EntityStorageInterface $storage) {
  31. $this->storage = $storage;
  32. }
  33.  
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public static function create(ContainerInterface $container, $base_plugin_id) {
  38. return new static(
  39. $container->get('entity.manager')->getStorage('node')
  40. );
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function getDerivativeDefinitions($base_plugin_definition) {
  46. $links = array();
  47.  
  48. $base_plugin_definition = array(
  49. 'enabled' => 1
  50. ) + $base_plugin_definition;
  51.  
  52. // use injected storage !
  53. $nodes = $this->storage->loadMultiple();
  54.  
  55. $links['custom_link'] = array (
  56. 'id' => 'custom_link',
  57. 'title' => t('Click me'),
  58. 'route_name' => 'entity.node.canonical',
  59. 'route_parameters' => array(
  60. 'nid' => 123,
  61. ),
  62. 'menu_name' => 'main',
  63. 'parent' => 'parent:menu:id',
  64. ) + $base_plugin_definition;
  65.  
  66. return $links;
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement