class PluginItemDeriver in Commerce Core 8.2
Deriver for the commerce_plugin_item field type.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\commerce\Plugin\Field\FieldType\PluginItemDeriver implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of PluginItemDeriver
File
- src/
Plugin/ Field/ FieldType/ PluginItemDeriver.php, line 16
Namespace
Drupal\commerce\Plugin\Field\FieldTypeView 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
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:: |
|
PluginItemDeriver:: |
protected | property | The event dispatcher. | |
PluginItemDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
PluginItemDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
PluginItemDeriver:: |
public | function | Constructs a new PluginItemDeriver object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |