You are here

class LocalTasks in RNG - Events and Registrations 8

Same name in this branch
  1. 8 src/Plugin/Derivative/LocalTasks.php \Drupal\rng\Plugin\Derivative\LocalTasks
  2. 8 rng_debug/src/Plugin/Derivative/LocalTasks.php \Drupal\rng_debug\Plugin\Derivative\LocalTasks
Same name and namespace in other branches
  1. 8.2 rng_debug/src/Plugin/Derivative/LocalTasks.php \Drupal\rng_debug\Plugin\Derivative\LocalTasks
  2. 3.x rng_debug/src/Plugin/Derivative/LocalTasks.php \Drupal\rng_debug\Plugin\Derivative\LocalTasks

Provides dynamic tasks.

Hierarchy

Expanded class hierarchy of LocalTasks

1 string reference to 'LocalTasks'
rng_debug.links.task.yml in rng_debug/rng_debug.links.task.yml
rng_debug/rng_debug.links.task.yml

File

rng_debug/src/Plugin/Derivative/LocalTasks.php, line 14

Namespace

Drupal\rng_debug\Plugin\Derivative
View source
class LocalTasks extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The RNG event manager.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $eventManager;

  /**
   * Constructs a LocalTasks object.
   *
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider.
   * @param \Drupal\rng\EventManagerInterface $event_manager
   *   The RNG event manager.
   */
  public function __construct(RouteProviderInterface $route_provider, EventManagerInterface $event_manager) {
    $this->routeProvider = $route_provider;
    $this->eventManager = $event_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('router.route_provider'), $container
      ->get('rng.event_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    $event_types = $this->eventManager
      ->getEventTypes();
    foreach (array_keys($event_types) as $entity_type) {

      // Only need one set of tasks task per 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"] = array(
          '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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
LocalTasks::$eventManager protected property The RNG event manager.
LocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
LocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
LocalTasks::__construct public function Constructs a LocalTasks object.