class PurchasedEntityConditionDeriver in Commerce Core 8.2
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\commerce_order\Plugin\Commerce\Condition\PurchasedEntityConditionDeriver implements ContainerDeriverInterface
Expanded class hierarchy of PurchasedEntityConditionDeriver
File
- modules/
order/ src/ Plugin/ Commerce/ Condition/ PurchasedEntityConditionDeriver.php, line 13
Namespace
Drupal\commerce_order\Plugin\Commerce\ConditionView source
class PurchasedEntityConditionDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new PurchasedEntityConditionDeriver object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
PurchasedEntityConditionDeriver:: |
protected | property | The entity type manager. | |
PurchasedEntityConditionDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
PurchasedEntityConditionDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
PurchasedEntityConditionDeriver:: |
public | function | Constructs a new PurchasedEntityConditionDeriver object. |