You are here

public function EntityUsageLocalTask::getDerivativeDefinitions in Entity Usage 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask::getDerivativeDefinitions()
  2. 8.2 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask::getDerivativeDefinitions()
  3. 8.3 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask::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/EntityUsageLocalTask.php, line 59

Class

EntityUsageLocalTask
Provides local task definitions for all entity types.

Namespace

Drupal\entity_usage\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];
  $configured_types = $this->config
    ->get('entity_usage.settings')
    ->get('local_task_enabled_entity_types') ?: [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('canonical')) {
      if (!in_array($entity_type_id, $configured_types)) {
        continue;
      }
      $this->derivatives["{$entity_type_id}.entity_usage"] = [
        'route_name' => "entity.{$entity_type_id}.entity_usage",
        'title' => $this
          ->t('Usage'),
        'base_route' => "entity.{$entity_type_id}.canonical",
        'weight' => 99,
      ];
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}