You are here

protected function CiviEntityStorage::doSaveFieldItems in CiviCRM Entity 8.3

Writes entity field values to the storage.

This method is responsible for allocating entity and revision identifiers and updating the entity object with their values.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity object.

string[] $names: (optional) The name of the fields to be written to the storage. If an empty value is passed all field values are saved.

Overrides SqlContentEntityStorage::doSaveFieldItems

1 call to CiviEntityStorage::doSaveFieldItems()
CiviEntityStorage::doSave in src/CiviEntityStorage.php
Performs storage-specific saving of the entity.

File

src/CiviEntityStorage.php, line 314

Class

CiviEntityStorage
Defines entity class for external CiviCRM entities.

Namespace

Drupal\civicrm_entity

Code

protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) {
  $update = !$entity
    ->isNew();
  $table_mapping = $this
    ->getTableMapping();
  $storage_definitions = $this
    ->getEntityFieldManager()
    ->getFieldStorageDefinitions($this->entityTypeId);
  $dedicated_table_fields = [];

  // Collect the name of fields to be written in dedicated tables and check
  // whether shared table records need to be updated.
  foreach ($names as $name) {
    $storage_definition = $storage_definitions[$name];
    if ($table_mapping
      ->requiresDedicatedTableStorage($storage_definition)) {
      $dedicated_table_fields[] = $name;
    }
  }

  // Update dedicated table records if necessary.
  if ($dedicated_table_fields) {
    $names = is_array($dedicated_table_fields) ? $dedicated_table_fields : [];
    $this
      ->saveToDedicatedTables($entity, $update, $names);
  }
}