function DatabaseStorage::doSetMultiple
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::doSetMultiple()
Saves key/value pairs.
This will be called by ::setMultiple() within a try block.
Parameters
array $data: An associative array of key/value pairs.
1 call to DatabaseStorage::doSetMultiple()
- DatabaseStorage::setMultiple in core/
lib/ Drupal/ Core/ KeyValueStore/ DatabaseStorage.php - Saves key/value pairs.
File
-
core/
lib/ Drupal/ Core/ KeyValueStore/ DatabaseStorage.php, line 189
Class
- DatabaseStorage
- Defines a default key/value store implementation.
Namespace
Drupal\Core\KeyValueStoreCode
protected function doSetMultiple(array $data) : void {
$query = $this->connection
->upsert($this->table)
->key([
'collection',
'name',
]);
$fieldsSet = FALSE;
foreach ($data as $key => $value) {
if (!$fieldsSet) {
$query->fields([
'collection' => $this->collection,
'name' => $key,
'value' => $this->serializer
->encode($value),
]);
$fieldsSet = TRUE;
continue;
}
$query->values([
'collection' => $this->collection,
'name' => $key,
'value' => $this->serializer
->encode($value),
]);
}
$query->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.