function StringDatabaseStorage::updateLocation

Same name in other branches
  1. 8.9.x core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::updateLocation()
  2. 10 core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::updateLocation()
  3. 11.x core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::updateLocation()

Update locations for string.

Parameters

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

1 call to StringDatabaseStorage::updateLocation()
StringDatabaseStorage::save in core/modules/locale/src/StringDatabaseStorage.php
Save string object to storage.

File

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

Class

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

Namespace

Drupal\locale

Code

protected function updateLocation($string) {
    if ($locations = $string->getLocations(TRUE)) {
        $created = FALSE;
        foreach ($locations as $type => $location) {
            foreach ($location as $name => $lid) {
                // Make sure that the name isn't longer than 255 characters.
                $name = substr($name, 0, 255);
                if (!$lid) {
                    $this->dbDelete('locales_location', [
                        'sid' => $string->getId(),
                        'type' => $type,
                        'name' => $name,
                    ])
                        ->execute();
                }
                elseif ($lid === TRUE) {
                    // This is a new location to add, take care not to duplicate.
                    $this->connection
                        ->merge('locales_location', $this->options)
                        ->keys([
                        'sid' => $string->getId(),
                        'type' => $type,
                        'name' => $name,
                    ])
                        ->fields([
                        'version' => \Drupal::VERSION,
                    ])
                        ->execute();
                    $created = TRUE;
                }
                // Loaded locations have 'lid' integer value, nor FALSE, nor TRUE.
            }
        }
        if ($created) {
            // As we've set a new location, check string version too.
            $this->checkVersion($string, \Drupal::VERSION);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.