You are here

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

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/LocalActions.php \Drupal\rng\Plugin\Derivative\LocalActions::getDerivativeDefinitions()
  2. 3.x src/Plugin/Derivative/LocalActions.php \Drupal\rng\Plugin\Derivative\LocalActions::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/LocalActions.php, line 65

Class

LocalActions
Provides dynamic local actions 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 actions per entity type.
    $this->derivatives["rng.event.{$entity_type}.event.access.reset"] = array(
      'title' => $this
        ->t('Reset/customize access rules'),
      'route_name' => "rng.event.{$entity_type}.access.reset",
      'class' => '\\Drupal\\rng\\Plugin\\Menu\\LocalAction\\ResetAccessRules',
      'appears_on' => array(
        "rng.event.{$entity_type}.access",
      ),
      'cache_tags' => $cache_tags,
    );
    $this->derivatives["rng.event.{$entity_type}.event.message.add"] = array(
      'title' => $this
        ->t('Add message'),
      'route_name' => "rng.event.{$entity_type}.messages.add",
      'appears_on' => array(
        "rng.event.{$entity_type}.messages",
      ),
      'cache_tags' => $cache_tags,
    );
    $this->derivatives["rng.event.{$entity_type}.event.group.add"] = array(
      'title' => $this
        ->t('Add group'),
      'route_name' => "rng.event.{$entity_type}.group.add",
      'appears_on' => array(
        "rng.event.{$entity_type}.group.list",
      ),
      'cache_tags' => $cache_tags,
    );
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}