protected function StringDatabaseStorage::dbStringInsert

Createds 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 ithrown.

1 call to StringDatabaseStorage::dbStringInsert()
StringDatabaseStorage::save in drupal/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php
Implements Drupal\locale\StringStorageInterface::save().

File

drupal/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php, line 464
Definition of Drupal\locale\StringDatabaseStorage.

Class

StringDatabaseStorage
Defines the locale string class.

Namespace

Drupal\locale

Code

protected function dbStringInsert($string) {
  if ($string
    ->isSource()) {
    $string
      ->setValues(array(
      'context' => '',
      'version' => 'none',
    ), FALSE);
    $fields = $string
      ->getValues(array(
      'source',
      'context',
      'version',
    ));
  }
  elseif ($string
    ->isTranslation()) {
    $string
      ->setValues(array(
      'customized' => 0,
    ), FALSE);
    $fields = $string
      ->getValues(array(
      'lid',
      'language',
      'translation',
      'customized',
    ));
  }
  if (!empty($fields)) {
    return $this->connection
      ->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(),
    )));
  }
}