You are here

public function LocalTasks::getDerivativeDefinitions in RNG - Events and Registrations 8

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

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/LocalTasks.php, line 69

Class

LocalTasks
Provides dynamic tasks for RNG.

Namespace

Drupal\rng\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];

  /** @var \Drupal\rng\Entity\EventType[] $event_types */
  foreach ($this->eventManager
    ->getEventTypes() as $entity_type => $event_types) {
    $cache_tags = $this->entityManager
      ->getDefinition($entity_type)
      ->getListCacheTags();
    foreach ($event_types as $event_type) {
      $cache_tags = Cache::mergeTags($cache_tags, $event_type
        ->getCacheTags());
    }

    // 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[$event_default] = array(
        'title' => t('Event', [], [
          'context' => 'rng',
        ]),
        'base_route' => "entity.{$entity_type}.canonical",
        'route_name' => "rng.event.{$entity_type}.event",
        'weight' => 30,
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.register.type_list"] = [
        'route_name' => "rng.event.{$entity_type}.register.type_list",
        'base_route' => "entity.{$entity_type}.canonical",
        'title' => t('Register', [], [
          'context' => 'rng',
        ]),
        'weight' => 40,
        'cache_tags' => $cache_tags,
      ];
      $this->derivatives["rng.event.{$entity_type}.register"] = [
        'route_name' => "rng.event.{$entity_type}.register",
        'parent_id' => 'rng.local_tasks:' . "rng.event.{$entity_type}.register.type_list",
        'title' => t('Register', [], [
          'context' => 'rng',
        ]),
        'weight' => 40,
        'cache_tags' => $cache_tags,
      ];
      $this->derivatives["rng.event.{$entity_type}.event.settings"] = array(
        'title' => t('Settings'),
        'route_name' => $this->derivatives[$event_default]['route_name'],
        'parent_id' => 'rng.local_tasks:' . $event_default,
        'weight' => -100,
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.event.access"] = array(
        'title' => t('Access'),
        'route_name' => "rng.event.{$entity_type}.access",
        'parent_id' => 'rng.local_tasks:' . $event_default,
        'weight' => -80,
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.event.messages"] = array(
        'title' => t('Messages'),
        'route_name' => "rng.event.{$entity_type}.messages",
        'parent_id' => 'rng.local_tasks:' . $event_default,
        'weight' => 100,
        'cache_tags' => $cache_tags,
      );
      $this->derivatives["rng.event.{$entity_type}.event.group.list"] = array(
        'title' => t('Groups', [], [
          'context' => 'rng',
        ]),
        'route_name' => "rng.event.{$entity_type}.group.list",
        'parent_id' => 'rng.local_tasks:' . $event_default,
        'weight' => 150,
        'cache_tags' => $cache_tags,
      );
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}