You are here

public function StringDatabaseStorage::save in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::save()

Save string object to storage.

Parameters

\Drupal\locale\StringInterface $string: The string object.

Return value

$this The called object.

Throws

\Drupal\locale\StringStorageException In case of failures, an exception is thrown.

Overrides StringStorageInterface::save

File

core/modules/locale/src/StringDatabaseStorage.php, line 115

Class

StringDatabaseStorage
Defines a class to store localized strings in the database.

Namespace

Drupal\locale

Code

public function save($string) {
  if ($string
    ->isNew()) {
    $result = $this
      ->dbStringInsert($string);
    if ($string
      ->isSource() && $result) {

      // Only for source strings, we set the locale identifier.
      $string
        ->setId($result);
    }
    $string
      ->setStorage($this);
  }
  else {
    $this
      ->dbStringUpdate($string);
  }

  // Update locations if they come with the string.
  $this
    ->updateLocation($string);
  return $this;
}