function StringDatabaseStorage::dbStringInsert
Same name in other branches
- 8.9.x core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringInsert()
- 10 core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringInsert()
- 11.x core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringInsert()
Creates a database record for a string object.
Parameters
\Drupal\locale\StringInterface $string: The string object.
Return value
bool|int If the operation failed, returns FALSE. If it succeeded returns the last insert ID of the query, if one exists.
Throws
\Drupal\locale\StringStorageException If the string is not suitable for this storage, an exception is thrown.
1 call to StringDatabaseStorage::dbStringInsert()
- StringDatabaseStorage::save in core/
modules/ locale/ src/ StringDatabaseStorage.php - Save string object to storage.
File
-
core/
modules/ locale/ src/ StringDatabaseStorage.php, line 465
Class
- StringDatabaseStorage
- Defines a class to store localized strings in the database.
Namespace
Drupal\localeCode
protected function dbStringInsert($string) {
if ($string->isSource()) {
$string->setValues([
'context' => '',
'version' => 'none',
], FALSE);
$fields = $string->getValues([
'source',
'context',
'version',
]);
}
elseif ($string->isTranslation()) {
$string->setValues([
'customized' => 0,
], FALSE);
$fields = $string->getValues([
'lid',
'language',
'translation',
'customized',
]);
}
if (!empty($fields)) {
return $this->connection
->insert($this->dbStringTable($string), $this->options)
->fields($fields)
->execute();
}
else {
throw new StringStorageException('The string cannot be saved: ' . $string->getString());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.