You are here

public function TransactionLocalAction::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/TransactionLocalAction.php, line 66

Class

TransactionLocalAction
Provides local action definitions for transaction list in target entities.

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);
    $this->derivatives["transaction.{$target_entity_type_id}.{$transaction_type_id}.add_transaction_action"] = [
      'route_name' => "entity.transaction.{$target_entity_type_id}.{$transaction_type_id}.add_form",
      'title' => $this
        ->t('Add @type transaction', [
        '@type' => $this->entityTypeManager
          ->getStorage('transaction_type')
          ->load($transaction_type_id)
          ->label(),
      ]),
      'appears_on' => [
        "entity.{$target_entity_type_id}.{$transaction_type_id}-transaction",
      ],
      'route_parameters' => [
        'target_entity_type' => $target_entity_type_id,
        'transaction_type' => $transaction_type_id,
      ],
    ];
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}