protected function StringDatabaseStorage::dbStringInsert in Localization update 7.2
Creates a database record for a string object.
Parameters
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
StringStorageException If the string is not suitable for this storage, an exception ithrown.
1 call to StringDatabaseStorage::dbStringInsert()
- StringDatabaseStorage::save in includes/
locale/ StringDatabaseStorage.php - Implements StringStorageInterface::save().
File
- includes/
locale/ StringDatabaseStorage.php, line 413 - Definition of StringDatabaseStorage.
Class
- StringDatabaseStorage
- Defines the locale string class.
Code
protected function dbStringInsert(StringInterface $string) {
if ($string
->isSource()) {
$string
->setValues(array(
'context' => '',
'version' => 'none',
), FALSE);
$fields = $string
->getValues(array(
'source',
'context',
'version',
'textgroup',
));
// @todo Add support for D7 fields 'location' and 'textgroup'.
}
elseif ($string
->isTranslation()) {
$string
->setValues(array(
'customized' => 0,
), FALSE);
$fields = $string
->getValues(array(
'lid',
'language',
'translation',
'plid',
'plural',
'customized',
));
}
if (!empty($fields)) {
// Change field 'customized' into 'l10n_status'. This enables the Drupal 8
// backported code to work with the Drupal 7 style database tables.
if (isset($fields['customized'])) {
$fields['l10n_status'] = $fields['customized'];
unset($fields['customized']);
}
return db_insert($this
->dbStringTable($string), $this->options)
->fields($fields)
->execute();
}
else {
throw new StringStorageException(format_string('The string cannot be saved: @string', array(
'@string' => $string
->getString(),
)));
}
}