protected function SqlContentEntityStorage::saveToSharedTables in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::saveToSharedTables()
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.
2 calls to SqlContentEntityStorage::saveToSharedTables()
- SqlContentEntityStorage::doSaveFieldItems in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Writes entity field values to the storage.
- SqlContentEntityStorage::restore in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Restores a previously saved entity.
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php, line 1018
Class
- SqlContentEntityStorage
- A content entity database storage implementation.
Namespace
Drupal\Core\Entity\SqlCode
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();
}