You are here

public function TransactionLocalTask::getDerivativeDefinitions in Transaction 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/TransactionLocalTask.php, line 66

Class

TransactionLocalTask
Provides local task definitions on applicable target entity types.

Namespace

Drupal\transaction\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];
  $tabs = $this->configFactory
    ->get('transaction.settings')
    ->get('tabs') ?: [];
  foreach ($tabs as $tab) {
    list($transaction_type_id, $target_entity_type_id) = explode('-', $tab);
    if (($target_entity_type = $this->entityTypeManager
      ->getDefinition($target_entity_type_id)) && $target_entity_type
      ->hasLinkTemplate("transaction-{$transaction_type_id}")) {
      $this->derivatives["{$target_entity_type_id}.{$transaction_type_id}.transaction_tab"] = [
        'route_name' => "entity.{$target_entity_type_id}.{$transaction_type_id}-transaction",
        'title' => $this->entityTypeManager
          ->getStorage('transaction_type')
          ->load($transaction_type_id)
          ->label(),
        'base_route' => "entity.{$target_entity_type_id}." . ($target_entity_type
          ->hasViewBuilderClass() && $target_entity_type
          ->hasLinkTemplate('canonical') ? "canonical" : "edit_form"),
        'weight' => 90,
      ];
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}