You are here

class PurchasedEntityConditionDeriver in Commerce Core 8.2

Hierarchy

Expanded class hierarchy of PurchasedEntityConditionDeriver

File

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

Namespace

Drupal\commerce_order\Plugin\Commerce\Condition
View 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

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
PurchasedEntityConditionDeriver::$entityTypeManager protected property The entity type manager.
PurchasedEntityConditionDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
PurchasedEntityConditionDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
PurchasedEntityConditionDeriver::__construct public function Constructs a new PurchasedEntityConditionDeriver object.