You are here

class PluginItemDeriver in Commerce Core 8.2

Deriver for the commerce_plugin_item field type.

Hierarchy

Expanded class hierarchy of PluginItemDeriver

File

src/Plugin/Field/FieldType/PluginItemDeriver.php, line 16

Namespace

Drupal\commerce\Plugin\Field\FieldType
View source
class PluginItemDeriver extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The event dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * Constructs a new PluginItemDeriver object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   */
  public function __construct($base_plugin_id, EventDispatcherInterface $event_dispatcher) {
    $this->basePluginId = $base_plugin_id;
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('event_dispatcher'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $plugin_types = [
      'commerce_condition' => $this
        ->t('Condition'),
      'commerce_promotion_offer' => $this
        ->t('Promotion offer'),
    ];

    // Core has no way to list plugin types, so each referenceable plugin
    // type needs to register itself via the event.
    $event = new ReferenceablePluginTypesEvent($plugin_types);
    $this->eventDispatcher
      ->dispatch(CommerceEvents::REFERENCEABLE_PLUGIN_TYPES, $event);
    $plugin_types = $event
      ->getPluginTypes();
    foreach ($plugin_types as $plugin_type => $label) {
      $this->derivatives[$plugin_type] = [
        'plugin_type' => $plugin_type,
        'label' => $label,
        'category' => $this
          ->t('Plugin'),
      ] + $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
PluginItemDeriver::$eventDispatcher protected property The event dispatcher.
PluginItemDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
PluginItemDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
PluginItemDeriver::__construct public function Constructs a new PluginItemDeriver object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.