class EntityConfigBase in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase
Class for importing configuration entities.
This class serves as the import class for most configuration entities. It can be necessary to provide a specific entity class if the configuration entity has a compound id (see EntityFieldEntity) or it has specific setter methods (see EntityDateFormat). When implementing an entity destination for the latter case, make sure to add a test not only for importing but also for re-importing (if that is supported).
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\migrate\Plugin\migrate\destination\DestinationBase implements MigrateDestinationInterface, RequirementsInterface
- class \Drupal\migrate\Plugin\migrate\destination\Entity implements DependentPluginInterface, ContainerFactoryPluginInterface uses DependencyTrait
- class \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase
- class \Drupal\migrate\Plugin\migrate\destination\Entity implements DependentPluginInterface, ContainerFactoryPluginInterface uses DependencyTrait
- class \Drupal\migrate\Plugin\migrate\destination\DestinationBase implements MigrateDestinationInterface, RequirementsInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of EntityConfigBase
7 files declare their use of EntityConfigBase
- EntityBlock.php in core/
modules/ block/ src/ Plugin/ migrate/ destination/ EntityBlock.php - Contains \Drupal\block\Plugin\migrate\destination\EntityBlock.
- EntityCommentType.php in core/
modules/ comment/ src/ Plugin/ migrate/ destination/ EntityCommentType.php - Contains \Drupal\comment\Plugin\migrate\destination\EntityCommentType.
- EntityDateFormat.php in core/
modules/ system/ src/ Plugin/ migrate/ destination/ EntityDateFormat.php - Contains \Drupal\system\Plugin\migrate\destination\EntityDateFormat.
- EntityImageStyle.php in core/
modules/ image/ src/ Plugin/ migrate/ destination/ EntityImageStyle.php - Contains \Drupal\image\Plugin\migrate\destination\EntityImageStyle.
- EntityNodeType.php in core/
modules/ node/ src/ Plugin/ migrate/ destination/ EntityNodeType.php - Contains \Drupal\node\Plugin\migrate\destination\EntityNodeType.
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityConfigBase.php, line 26 - Contains \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase.
Namespace
Drupal\migrate\Plugin\migrate\destinationView source
class EntityConfigBase extends Entity {
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
if ($row
->isStub()) {
throw new MigrateException('Config entities can not be stubbed.');
}
$this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
$ids = $this
->getIds();
$id_key = $this
->getKey('id');
if (count($ids) > 1) {
// Ids is keyed by the key name so grab the keys.
$id_keys = array_keys($ids);
if (!$row
->getDestinationProperty($id_key)) {
// Set the id into the destination in for form "val1.val2.val3".
$row
->setDestinationProperty($id_key, $this
->generateId($row, $id_keys));
}
}
$entity = $this
->getEntity($row, $old_destination_id_values);
$entity
->save();
if (count($ids) > 1) {
// This can only be a config entity, content entities have their id key
// and that's it.
$return = array();
foreach ($id_keys as $id_key) {
$return[] = $entity
->get($id_key);
}
return $return;
}
return array(
$entity
->id(),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$id_key = $this
->getKey('id');
$ids[$id_key]['type'] = 'string';
return $ids;
}
/**
* Updates an entity with the contents of a row.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to update.
* @param \Drupal\migrate\Row $row
* The row object to update from.
*/
protected function updateEntity(EntityInterface $entity, Row $row) {
foreach ($row
->getRawDestination() as $property => $value) {
$this
->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value);
}
$this
->setRollbackAction($row
->getIdMap());
}
/**
* Updates a (possible nested) entity property with a value.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The config entity.
* @param array $parents
* The array of parents.
* @param string|object $value
* The value to update to.
*/
protected function updateEntityProperty(EntityInterface $entity, array $parents, $value) {
$top_key = array_shift($parents);
$entity_value = $entity
->get($top_key);
if (is_array($entity_value)) {
NestedArray::setValue($entity_value, $parents, $value);
}
else {
$entity_value = $value;
}
$entity
->set($top_key, $entity_value);
}
/**
* Generate an entity id.
*
* @param \Drupal\migrate\Row $row
* The current row.
* @param array $ids
* The destination ids.
*
* @return string
* The generated entity id.
*/
protected function generateId(Row $row, array $ids) {
$id_values = array();
foreach ($ids as $id) {
$id_values[] = $row
->getDestinationProperty($id);
}
return implode('.', $id_values);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | 1 |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
DestinationBase:: |
protected | property | The migration. | |
DestinationBase:: |
protected | property | The rollback action to be saved for the last imported item. | |
DestinationBase:: |
protected | property | Indicates whether the destination can be rolled back. | |
DestinationBase:: |
public | function |
Checks if requirements for this plugin are OK. Overrides RequirementsInterface:: |
|
DestinationBase:: |
public | function |
The rollback action for the last imported item. Overrides MigrateDestinationInterface:: |
|
DestinationBase:: |
protected | function | For a destination item being updated, set the appropriate rollback action. | |
DestinationBase:: |
public | function |
Whether the destination can be rolled back or not. Overrides MigrateDestinationInterface:: |
|
Entity:: |
protected | property | The list of the bundles of this entity type. | |
Entity:: |
protected | property | The entity storage. | 1 |
Entity:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
Entity:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
Entity:: |
public | function |
Returns an array of destination fields. Overrides MigrateDestinationInterface:: |
|
Entity:: |
protected | function | Creates or loads an entity. | 5 |
Entity:: |
protected | function | Get the entity id of the row. | 2 |
Entity:: |
protected static | function | Finds the entity type from configuration or plugin id. | 3 |
Entity:: |
protected | function | Returns a specific entity key. | |
Entity:: |
public | function |
Delete the specified destination object from the target Drupal. Overrides DestinationBase:: |
|
Entity:: |
public | function |
Construct a new entity. Overrides DestinationBase:: |
|
EntityConfigBase:: |
protected | function | Generate an entity id. | |
EntityConfigBase:: |
public | function |
Get the destination ids. Overrides MigrateDestinationInterface:: |
3 |
EntityConfigBase:: |
public | function |
Import the row. Overrides MigrateDestinationInterface:: |
3 |
EntityConfigBase:: |
protected | function | Updates an entity with the contents of a row. | 1 |
EntityConfigBase:: |
protected | function | Updates a (possible nested) entity property with a value. | 1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 2 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
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:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | |
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. |