You are here

public function DynamicLocalTasks::getDerivativeDefinitions in Entity Clone 8

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 56

Class

DynamicLocalTasks
Defines dynamic local tasks.

Namespace

Drupal\entity_clone\Plugin\Derivative

Code

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

  /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $has_clone_path = $entity_type
      ->hasLinkTemplate('clone-form');
    $has_canonical_path = $entity_type
      ->hasLinkTemplate('canonical');
    if ($has_clone_path) {
      $this->derivatives["{$entity_type_id}.clone_tab"] = [
        'route_name' => "entity.{$entity_type_id}.clone_form",
        'title' => $this->translationManager
          ->translate('Clone'),
        'base_route' => "entity.{$entity_type_id}." . ($has_canonical_path ? "canonical" : "edit_form"),
        'weight' => 100,
      ];
    }
  }
  return $this->derivatives;
}