function EntityContentBase::updateEntity
Same name in other branches
- 9 core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::updateEntity()
- 8.9.x core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::updateEntity()
- 11.x core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::updateEntity()
Overrides Entity::updateEntity
3 calls to EntityContentBase::updateEntity()
- Book::updateEntity in core/
modules/ book/ src/ Plugin/ migrate/ destination/ Book.php - Updates an entity with the new values from row.
- EntityContentComplete::updateEntity in core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityContentComplete.php - Updates an entity with the new values from row.
- EntityRevision::getEntity in core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityRevision.php - Gets the entity.
3 methods override EntityContentBase::updateEntity()
- Book::updateEntity in core/
modules/ book/ src/ Plugin/ migrate/ destination/ Book.php - Updates an entity with the new values from row.
- EntityContentComplete::updateEntity in core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityContentComplete.php - Updates an entity with the new values from row.
- EntityRevision::updateEntity in core/
modules/ migrate/ tests/ src/ Unit/ destination/ EntityRevisionTest.php - Don't test method from base class.
File
-
core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityContentBase.php, line 271
Class
- EntityContentBase
- Provides destination class for all content entities lacking a specific class.
Namespace
Drupal\migrate\Plugin\migrate\destinationCode
protected function updateEntity(EntityInterface $entity, Row $row) {
$empty_destinations = $row->getEmptyDestinationProperties();
// By default, an update will be preserved.
$rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE;
// Make sure we have the right translation.
if ($this->isTranslationDestination()) {
$property = $this->storage
->getEntityType()
->getKey('langcode');
if ($row->hasDestinationProperty($property)) {
$language = $row->getDestinationProperty($property);
if (!$entity->hasTranslation($language)) {
$entity->addTranslation($language);
// We're adding a translation, so delete it on rollback.
$rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE;
}
$entity = $entity->getTranslation($language);
}
}
// If the migration has specified a list of properties to be overwritten,
// clone the row with an empty set of destination values, and re-add only
// the specified properties.
if (isset($this->configuration['overwrite_properties'])) {
$empty_destinations = array_intersect($empty_destinations, $this->configuration['overwrite_properties']);
$clone = $row->cloneWithoutDestination();
foreach ($this->configuration['overwrite_properties'] as $property) {
$clone->setDestinationProperty($property, $row->getDestinationProperty($property));
}
$row = $clone;
}
foreach ($row->getDestination() as $field_name => $values) {
$field = $entity->{$field_name};
if ($field instanceof TypedDataInterface) {
$field->setValue($values);
}
}
foreach ($empty_destinations as $field_name) {
$entity->{$field_name} = NULL;
}
$this->setRollbackAction($row->getIdMap(), $rollback_action);
// We might have a different (translated) entity, so return it.
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.