You are here

public function ConfigEntityStorage::updateFromStorageRecord in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php \Drupal\Core\Config\Entity\ConfigEntityStorage::updateFromStorageRecord()

Updates a configuration entity from storage values.

Allows the configuration entity storage to massage storage values before updating an entity.

Parameters

ConfigEntityInterface $entity: The configuration entity to update.

array $values: The array of values from the configuration storage.

Return value

ConfigEntityInterface The configuration entity.

Overrides ConfigEntityStorageInterface::updateFromStorageRecord

See also

\Drupal\Core\Entity\EntityStorageBase::mapFromStorageRecords()

\Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords()

1 call to ConfigEntityStorage::updateFromStorageRecord()
ConfigEntityStorage::importUpdate in core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
Updates entities upon synchronizing configuration changes.

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php, line 447

Class

ConfigEntityStorage
Defines the storage class for configuration entities.

Namespace

Drupal\Core\Config\Entity

Code

public function updateFromStorageRecord(ConfigEntityInterface $entity, array $values) {
  $entity->original = clone $entity;
  $data = $this
    ->mapFromStorageRecords([
    $values,
  ]);
  $updated_entity = current($data);

  /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
  $entity_type = $this
    ->getEntityType();
  $id_key = $entity_type
    ->getKey('id');
  $properties = $entity_type
    ->getPropertiesToExport($updated_entity
    ->get($id_key));
  if (empty($properties)) {

    // Fallback to using the provided values. If the properties cannot be
    // determined for the config entity type annotation or configuration
    // schema.
    $properties = array_keys($values);
  }
  foreach ($properties as $property) {
    if ($property === $this->uuidKey) {

      // During an update the UUID field should not be copied. Under regular
      // circumstances the values will be equal. If configuration is written
      // twice during configuration install the updated entity will not have a
      // UUID.
      // @see \Drupal\Core\Config\ConfigInstaller::createConfiguration()
      continue;
    }
    $entity
      ->set($property, $updated_entity
      ->get($property));
  }
  return $entity;
}