SqlContentEntityStorage::saveToSharedTables

protected SqlContentEntityStorage::saveToSharedTables(ContentEntityInterface $entity, $table_name = NULL, $new_revision = NULL)

Saves fields that use the shared tables.

Parameters

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

string $table_name: (optional) The table name to save to. Defaults to the data table.

bool $new_revision: (optional) Whether we are dealing with a new revision. By default fetches the information from the entity object.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 888

Class

SqlContentEntityStorage
A content entity database storage implementation.

Namespace

Drupal\Core\Entity\Sql

Code

protected function saveToSharedTables(ContentEntityInterface $entity, $table_name = NULL, $new_revision = NULL) {
  if (!isset($table_name)) {
    $table_name = $this->dataTable;
  }
  if (!isset($new_revision)) {
    $new_revision = $entity->isNewRevision();
  }
  $revision = $table_name != $this->dataTable;

  if (!$revision || !$new_revision) {
    $key = $revision ? $this->revisionKey : $this->idKey;
    $value = $revision ? $entity->getRevisionId() : $entity->id();
    // Delete and insert to handle removed values.
    $this->database->delete($table_name)
      ->condition($key, $value)
      ->execute();
  }

  $query = $this->database->insert($table_name);

  foreach ($entity->getTranslationLanguages() as $langcode => $language) {
    $translation = $entity->getTranslation($langcode);
    $record = $this->mapToDataStorageRecord($translation, $table_name);
    $values = (array) $record;
    $query
    ->fields(array_keys($values))
      ->values($values);
  }

  $query->execute();
}
doc_Drupal
2016-10-29 09:43:30
Comments
Leave a Comment

Please login to continue.