class CreateQuantity in farmOS 2.x
Create quantity entities.
This is an alternative to using the entity_generate process plugin which requires a "lookup" to happen before creating the entity. Since the quantity value field is a Fraction field, it is easier to use our own process plugin.
Plugin annotation
@MigrateProcessPlugin(
id = "create_quantity"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\quantity\Plugin\migrate\process\CreateQuantity implements ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CreateQuantity
File
- modules/
core/ quantity/ src/ Plugin/ migrate/ process/ CreateQuantity.php, line 23
Namespace
Drupal\quantity\Plugin\migrate\processView source
class CreateQuantity extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* Quantity entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $quantityStorage;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);
$instance->quantityStorage = $container
->get('entity_type.manager')
->getStorage('quantity');
return $instance;
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Start array of entity values.
$entity_values = [];
// Gather any static default values for properties/fields.
if (isset($this->configuration['default_values']) && is_array($this->configuration['default_values'])) {
foreach ($this->configuration['default_values'] as $key => $value) {
$entity_values[$key] = $value;
}
}
// Gather any additional properties/fields.
if (isset($this->configuration['values']) && is_array($this->configuration['values'])) {
foreach ($this->configuration['values'] as $key => $property) {
$source_value = $row
->get($property);
NestedArray::setValue($entity_values, explode(Row::PROPERTY_SEPARATOR, $key), $source_value, TRUE);
}
}
// Create the entity.
$entity = $this->quantityStorage
->create($entity_values);
// Save the entity so it has an ID.
$entity
->save();
// Return entity.
return $entity;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CreateQuantity:: |
protected | property | Quantity entity storage. | |
CreateQuantity:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
CreateQuantity:: |
public | function |
Performs the associated process. Overrides ProcessPluginBase:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |