You are here

public function DynamicLocalTasks::getDerivativeDefinitions in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\entity_hierarchy\Plugin\Derivative\DynamicLocalTasks::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/DynamicLocalTasks.php, line 73

Class

DynamicLocalTasks
Generates children tab for relevant entities.

Namespace

Drupal\entity_hierarchy\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];
  foreach ($this->entityFieldManager
    ->getFieldMapByFieldType('entity_reference_hierarchy') as $entity_type_id => $fields) {

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);
    if (!$entity_type
      ->hasLinkTemplate('canonical') || isset($this->derivatives["{$entity_type_id}.entity_hierarchy_reorder"])) {
      continue;
    }
    $this->derivatives["{$entity_type_id}.entity_hierarchy_reorder"] = [
      'route_name' => "entity.{$entity_type_id}.entity_hierarchy_reorder",
      'title' => $this
        ->t('Children'),
      'base_route' => "entity.{$entity_type_id}.canonical",
      'weight' => 30,
    ] + $base_plugin_definition;
  }
  return $this->derivatives;
}