You are here

public function StringDatabaseStorage::delete in Drupal 8

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

Delete string from 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::delete

File

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

Class

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

Namespace

Drupal\locale

Code

public function delete($string) {
  if ($keys = $this
    ->dbStringKeys($string)) {
    $this
      ->dbDelete('locales_target', $keys)
      ->execute();
    if ($string
      ->isSource()) {
      $this
        ->dbDelete('locales_source', $keys)
        ->execute();
      $this
        ->dbDelete('locales_location', $keys)
        ->execute();
      $string
        ->setId(NULL);
    }
  }
  else {
    throw new StringStorageException('The string cannot be deleted because it lacks some key fields: ' . $string
      ->getString());
  }
  return $this;
}