W3cubDocs

/Drupal 8

protected function 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 874

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Sql!SqlContentEntityStorage.php/function/SqlContentEntityStorage::saveToSharedTables/8.1.x