You are here

public function PurchasedEntityConditionDeriver::getDerivativeDefinitions in Commerce Core 8.2

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

modules/order/src/Plugin/Commerce/Condition/PurchasedEntityConditionDeriver.php, line 44

Class

PurchasedEntityConditionDeriver

Namespace

Drupal\commerce_order\Plugin\Commerce\Condition

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $purchasable_entity_types = array_filter($this->entityTypeManager
    ->getDefinitions(), static function (EntityTypeInterface $entity_type) {
    return $entity_type
      ->entityClassImplements(PurchasableEntityInterface::class);
  });
  foreach ($purchasable_entity_types as $purchasable_entity_type_id => $purchasable_entity_type) {
    if ($base_plugin_definition['entity_type'] === 'commerce_order') {
      $display_label = new TranslatableMarkup('Order contains specific :item', [
        ':item' => $purchasable_entity_type
          ->getPluralLabel(),
      ]);
    }
    else {
      $display_label = new TranslatableMarkup('Specific :item', [
        ':item' => $purchasable_entity_type
          ->getSingularLabel(),
      ]);
    }
    $this->derivatives[$purchasable_entity_type_id] = [
      'label' => $purchasable_entity_type
        ->getLabel(),
      'display_label' => $display_label,
      'purchasable_entity_type' => $purchasable_entity_type_id,
    ] + $base_plugin_definition;
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}