You are here

public function EntityUsageLocalTask::getDerivativeDefinitions in Entity Usage 8.4

Same name and namespace in other branches
  1. 8 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) {

    // We prefer the canonical template, but we also allow edit-form templates
    // on entities that don't have canonical (like views, etc).
    if ($entity_type
      ->hasLinkTemplate('canonical')) {
      $template_key = 'canonical';
    }
    elseif ($entity_type
      ->hasLinkTemplate('edit-form')) {
      $template_key = 'edit_form';
    }
    if (!empty($template_key)) {
      if (!in_array($entity_type_id, $configured_types, TRUE)) {
        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}.{$template_key}",
        'weight' => 99,
      ];
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}