class EntityReferenceRevisions in Entity Reference Revisions 8
Same name in this branch
- 8 src/Plugin/DataType/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\DataType\EntityReferenceRevisions
- 8 src/Plugin/views/display/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\views\display\EntityReferenceRevisions
- 8 src/Plugin/views/style/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\views\style\EntityReferenceRevisions
- 8 src/Plugin/views/row/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\views\row\EntityReferenceRevisions
- 8 src/Plugin/migrate/destination/EntityReferenceRevisions.php \Drupal\entity_reference_revisions\Plugin\migrate\destination\EntityReferenceRevisions
Provides entity_reference_revisions destination plugin.
Available configuration keys:
- new_revisions: (optional) Flag to indicate if a new revision should be created instead of updating a previous default record. Only applicable when providing an entity id without a revision_id.
- force_revision: (optional) Flag to ignore other checks and always create a revision.
Plugin annotation
@MigrateDestination(
id = "entity_reference_revisions",
deriver = "Drupal\entity_reference_revisions\Plugin\Derivative\MigrateEntityReferenceRevisions"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\Plugin\migrate\destination\DestinationBase implements MigrateDestinationInterface, RequirementsInterface
- class \Drupal\migrate\Plugin\migrate\destination\Entity implements DependentPluginInterface, ContainerFactoryPluginInterface uses DependencyTrait, EntityFieldDefinitionTrait
- class \Drupal\migrate\Plugin\migrate\destination\EntityContentBase implements HighestIdInterface, MigrateValidatableEntityInterface uses DeprecatedServicePropertyTrait
- class \Drupal\migrate\Plugin\migrate\destination\EntityRevision
- class \Drupal\entity_reference_revisions\Plugin\migrate\destination\EntityReferenceRevisions implements ConfigurableInterface
- class \Drupal\migrate\Plugin\migrate\destination\EntityRevision
- class \Drupal\migrate\Plugin\migrate\destination\EntityContentBase implements HighestIdInterface, MigrateValidatableEntityInterface uses DeprecatedServicePropertyTrait
- class \Drupal\migrate\Plugin\migrate\destination\Entity implements DependentPluginInterface, ContainerFactoryPluginInterface uses DependencyTrait, EntityFieldDefinitionTrait
- class \Drupal\migrate\Plugin\migrate\destination\DestinationBase implements MigrateDestinationInterface, RequirementsInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of EntityReferenceRevisions
2 files declare their use of EntityReferenceRevisions
- EntityReferenceRevisionsDeriverTest.php in tests/
src/ Kernel/ Plugin/ Derivative/ EntityReferenceRevisionsDeriverTest.php - MigrateEntityReferenceRevisions.php in src/
Plugin/ Derivative/ MigrateEntityReferenceRevisions.php
File
- src/
Plugin/ migrate/ destination/ EntityReferenceRevisions.php, line 28
Namespace
Drupal\entity_reference_revisions\Plugin\migrate\destinationView source
class EntityReferenceRevisions extends EntityRevision implements ConfigurableInterface {
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'new_revisions' => FALSE,
];
}
/**
* {@inheritdoc}
*/
protected static function getEntityTypeId($pluginId) {
// Remove "entity_reference_revisions:".
// Ideally, we would call getDerivativeId(), but since this is static
// that is not possible so we follow the same pattern as core.
return substr($pluginId, 27);
}
/**
* {@inheritdoc}
*/
protected function save(ContentEntityInterface $entity, array $oldDestinationIdValues = []) {
$entity
->save();
return [
$this
->getKey('id') => $entity
->id(),
$this
->getKey('revision') => $entity
->getRevisionId(),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
if ($revision_key = $this
->getKey('revision')) {
$id_key = $this
->getKey('id');
$ids[$id_key]['type'] = 'integer';
// TODO: Improve after https://www.drupal.org/node/2783715 is finished.
$ids[$revision_key]['type'] = 'integer';
if ($this
->isTranslationDestination()) {
if ($revision_key = $this
->getKey('langcode')) {
$ids[$revision_key]['type'] = 'string';
}
else {
throw new MigrateException('This entity type does not support translation.');
}
}
return $ids;
}
throw new MigrateException('This entity type does not support revisions.');
}
/**
* {@inheritdoc}
*/
protected function getEntity(Row $row, array $oldDestinationIdValues) {
$entity_id = $oldDestinationIdValues ? array_shift($oldDestinationIdValues) : $this
->getEntityId($row);
$configuration = $this
->getConfiguration();
if (isset($configuration['force_revision']) && $configuration['force_revision'] == TRUE) {
$revision_id = NULL;
}
else {
$revision_id = $oldDestinationIdValues ? array_pop($oldDestinationIdValues) : $row
->getDestinationProperty($this
->getKey('revision'));
}
// If a specific revision_id is supplied and exists, assert the entity_id
// matches (if supplied), and update the revision.
/** @var \Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\EntityInterface $entity */
if (!empty($revision_id) && ($entity = $this->storage
->loadRevision($revision_id))) {
if (!empty($entity_id) && $entity
->id() != $entity_id) {
throw new MigrateException("The revision_id exists for this entity type, but does not belong to the given entity id");
}
$entity = $this
->updateEntity($entity, $row) ?: $entity;
}
elseif (!empty($entity_id) && ($entity = $this->storage
->load($entity_id))) {
// If so configured, create a new revision while updating.
if (!empty($this->configuration['new_revisions'])) {
$entity
->setNewRevision(TRUE);
}
$entity = $this
->updateEntity($entity, $row) ?: $entity;
}
else {
// Attempt to ensure we always have a bundle.
if ($bundle = $this
->getBundle($row)) {
$row
->setDestinationProperty($this
->getKey('bundle'), $bundle);
}
// Stubs might need some required fields filled in.
if ($row
->isStub()) {
$this
->processStubRow($row);
}
$entity = $this->storage
->create($row
->getDestination())
->enforceIsNew(TRUE);
$entity
->setNewRevision(TRUE);
}
$this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
return $entity;
}
/**
* {@inheritdoc}
*/
public function rollback(array $destination_identifiers) {
if ($this
->isTranslationDestination()) {
$this
->rollbackTranslation($destination_identifiers);
}
else {
$this
->rollbackNonTranslation($destination_identifiers);
}
}
/**
* Rollback translation destinations.
*
* @param array $destination_identifiers
* The IDs of the destination object to delete.
*/
protected function rollbackTranslation(array $destination_identifiers) {
$entity = $this->storage
->loadRevision(array_pop($destination_identifiers));
if ($entity && $entity instanceof TranslatableInterface) {
if ($key = $this
->getKey('langcode')) {
if (isset($destination_identifiers[$key])) {
$langcode = $destination_identifiers[$key];
if ($entity
->hasTranslation($langcode)) {
// Make sure we don't remove the default translation.
$translation = $entity
->getTranslation($langcode);
if (!$translation
->isDefaultTranslation()) {
$entity
->removeTranslation($langcode);
$entity
->save();
}
}
}
}
}
}
/**
* Rollback non-translation destinations.
*
* @param array $destination_identifiers
* The IDs of the destination object to delete.
*/
protected function rollbackNonTranslation(array $destination_identifiers) {
$revision_id = array_pop($destination_identifiers);
$entity = $this->storage
->loadRevision($revision_id);
if ($entity) {
if ($entity
->isDefaultRevision()) {
$entity
->delete();
}
else {
$this->storage
->deleteRevision($revision_id);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
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. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
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 |
Gets the destination module handling the destination data. Overrides MigrateDestinationInterface:: |
1 |
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. | |
Entity:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
Entity:: |
public | function |
Returns an array of destination fields. Overrides MigrateDestinationInterface:: |
|
Entity:: |
public | function | Gets the bundle for the row taking into account the default. | |
Entity:: |
protected | function | Gets the entity ID of the row. | 2 |
Entity:: |
protected | function | Returns a specific entity key. | |
EntityContentBase:: |
protected | property | ||
EntityContentBase:: |
protected | property | Entity field manager. | |
EntityContentBase:: |
protected | property | Field type plugin manager. | |
EntityContentBase:: |
public static | function |
Creates an instance of the plugin. Overrides Entity:: |
2 |
EntityContentBase:: |
public | function |
Overrides MigrateDestinationInterface:: |
3 |
EntityContentBase:: |
public | function |
Returns a state of whether an entity needs to be validated before saving. Overrides MigrateValidatableEntityInterface:: |
|
EntityContentBase:: |
public | function | ||
EntityContentBase:: |
protected | function | Populates as much of the stub row as possible. | 3 |
EntityContentBase:: |
protected | function | Updates an entity with the new values from row. | 3 |
EntityContentBase:: |
public | function |
Validates the entity. Overrides MigrateValidatableEntityInterface:: |
|
EntityFieldDefinitionTrait:: |
protected | function | Gets the field definition from a specific entity base field. | |
EntityReferenceRevisions:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
EntityReferenceRevisions:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
EntityReferenceRevisions:: |
protected | function |
Gets the entity. Overrides EntityRevision:: |
|
EntityReferenceRevisions:: |
protected static | function |
Finds the entity type from configuration or plugin ID. Overrides EntityFieldDefinitionTrait:: |
|
EntityReferenceRevisions:: |
public | function |
Gets the destination IDs. Overrides EntityRevision:: |
|
EntityReferenceRevisions:: |
public | function |
Delete the specified destination object from the target Drupal. Overrides EntityContentBase:: |
|
EntityReferenceRevisions:: |
protected | function | Rollback non-translation destinations. | |
EntityReferenceRevisions:: |
protected | function | Rollback translation destinations. | |
EntityReferenceRevisions:: |
protected | function |
Saves the entity. Overrides EntityRevision:: |
|
EntityReferenceRevisions:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
EntityRevision:: |
public | function |
Returns the highest ID tracked by the implementing plugin. Overrides EntityContentBase:: |
|
EntityRevision:: |
public | function |
Constructs a content entity. Overrides EntityContentBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |