function EntityConfigBase::updateEntity

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::updateEntity()
  2. 10 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::updateEntity()
  3. 11.x 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.

Throws

\LogicException Thrown if the destination is for translations and either the "property" or "translation" property does not exist.

1 call to EntityConfigBase::updateEntity()
EntitySearchPage::updateEntity in core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php
Updates the 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 the entity with the contents of a row.

File

core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php, line 200

Class

EntityConfigBase
Base destination class for importing configuration entities.

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

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());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.