public function ContentImporter::prepareEntity in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Importer/ContentImporter.php \Drupal\content_sync\Importer\ContentImporter::prepareEntity()
1 call to ContentImporter::prepareEntity()
- ContentImporter::syncEntity in src/
Importer/ ContentImporter.php - Synchronize a given entity.
File
- src/
Importer/ ContentImporter.php, line 221
Class
Namespace
Drupal\content_sync\ImporterCode
public function prepareEntity(ContentEntityInterface $entity) {
$uuid = $entity
->uuid();
$original_entity = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->loadByProperties([
'uuid' => $uuid,
]);
if (!empty($original_entity)) {
$original_entity = reset($original_entity);
if (!$this->updateEntities) {
return $original_entity;
}
// Overwrite the received properties.
if (!empty($entity->_restSubmittedFields)) {
foreach ($entity->_restSubmittedFields as $field_name) {
if ($this
->isValidEntityField($original_entity, $entity, $field_name)) {
$original_entity
->set($field_name, $entity
->get($field_name)
->getValue());
}
}
}
return $this
->processSerializedFields($original_entity);
}
$duplicate = $entity
->createDuplicate();
$entity_type = $entity
->getEntityType();
$duplicate->{$entity_type
->getKey('uuid')}->value = $uuid;
return $this
->processSerializedFields($duplicate);
}