LocalTasks.php in RNG - Events and Registrations 8.2
File
rng_debug/src/Plugin/Derivative/LocalTasks.php
View source
<?php
namespace Drupal\rng_debug\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\rng\EventManagerInterface;
class LocalTasks extends DeriverBase implements ContainerDeriverInterface {
protected $eventManager;
public function __construct(RouteProviderInterface $route_provider, EventManagerInterface $event_manager) {
$this->routeProvider = $route_provider;
$this->eventManager = $event_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('router.route_provider'), $container
->get('rng.event_manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
$event_types = $this->eventManager
->getEventTypes();
foreach (array_keys($event_types) as $entity_type) {
if ($this->routeProvider
->getRouteByName("entity.{$entity_type}.canonical")) {
$event_default = "rng.event.{$entity_type}.event.default";
$this->derivatives["rng.event.{$entity_type}.event.rules"] = [
'title' => t('Rules'),
'route_name' => "rng.event.{$entity_type}.rules",
'parent_id' => 'rng.local_tasks:' . $event_default,
'weight' => 20,
];
}
}
foreach ($this->derivatives as &$entry) {
$entry += $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}