function EntityConfigBase::updateEntity
Same name in other branches
- 9 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::updateEntity()
- 8.9.x core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::updateEntity()
- 10 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::updateEntity()
Updates an entity with the contents of a row.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to update.
\Drupal\migrate\Row $row: The row object to update from.
Return value
\Drupal\Core\Entity\EntityInterface An updated entity from row values.
Throws
\LogicException Thrown if the destination is for translations and either the "property" or "translation" property does not exist.
Overrides Entity::updateEntity
1 call to EntityConfigBase::updateEntity()
- EntitySearchPage::updateEntity in core/
modules/ search/ src/ Plugin/ migrate/ destination/ EntitySearchPage.php - Updates an entity with the contents of a row.
1 method overrides EntityConfigBase::updateEntity()
- EntitySearchPage::updateEntity in core/
modules/ search/ src/ Plugin/ migrate/ destination/ EntitySearchPage.php - Updates an entity with the contents of a row.
File
-
core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityConfigBase.php, line 203
Class
- EntityConfigBase
- Base destination class for importing configuration entities.
Namespace
Drupal\migrate\Plugin\migrate\destinationCode
protected function updateEntity(EntityInterface $entity, Row $row) {
// This is a translation if the language in the active config does not
// match the language of this row.
$translation = FALSE;
if ($this->isTranslationDestination() && $row->hasDestinationProperty('langcode') && $this->languageManager instanceof ConfigurableLanguageManager) {
$config = $entity->getConfigDependencyName();
$langcode = $this->configFactory
->get('langcode');
if ($langcode != $row->getDestinationProperty('langcode')) {
$translation = TRUE;
}
}
if ($translation) {
if (!$row->hasDestinationProperty('property')) {
throw new \LogicException('The "property" property is required');
}
if (!$row->hasDestinationProperty('translation')) {
throw new \LogicException('The "translation" property is required');
}
$config_override = $this->languageManager
->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $config);
$config_override->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $row->getDestinationProperty('property')), $row->getDestinationProperty('translation'));
$config_override->save();
}
else {
foreach ($row->getRawDestination() as $property => $value) {
$this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value);
}
$this->setRollbackAction($row->getIdMap());
}
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.