Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace DrupalYOUR_MODULEPluginDerivative;
- use DrupalComponentPluginDerivativeDeriverBase;
- use DrupalCorePluginDiscoveryContainerDeriverInterface;
- use DrupalCoreEntityEntityStorageInterface;
- use SymfonyComponentDependencyInjectionContainerInterface;
- /**
- * Provides menu links.
- */
- class MyLinks extends DeriverBase implements ContainerDeriverInterface {
- /**
- * The team storage.
- *
- * @var DrupalCoreEntityEntityStorageInterface
- */
- protected $myStorage;
- /**
- * Constructs a XX instance.
- *
- * @param DrupalCoreEntityEntityStorageInterface $storage
- * The storage.
- */
- public function __construct(EntityStorageInterface $storage) {
- $this->storage = $storage;
- }
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, $base_plugin_id) {
- return new static(
- $container->get('entity.manager')->getStorage('node')
- );
- }
- /**
- * {@inheritdoc}
- */
- public function getDerivativeDefinitions($base_plugin_definition) {
- $links = array();
- $base_plugin_definition = array(
- 'enabled' => 1
- ) + $base_plugin_definition;
- // use injected storage !
- $nodes = $this->storage->loadMultiple();
- $links['custom_link'] = array (
- 'id' => 'custom_link',
- 'title' => t('Click me'),
- 'route_name' => 'entity.node.canonical',
- 'route_parameters' => array(
- 'nid' => 123,
- ),
- 'menu_name' => 'main',
- 'parent' => 'parent:menu:id',
- ) + $base_plugin_definition;
- return $links;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement