class StringDatabaseStorageDecorator in Language Hierarchy 2.x
Decorates the locale.storage service.
Hierarchy
- class \Drupal\locale\StringDatabaseStorage implements StringStorageInterface
- class \Drupal\language_hierarchy\StringDatabaseStorageDecorator uses DependencySerializationTrait
Expanded class hierarchy of StringDatabaseStorageDecorator
File
- src/
StringDatabaseStorageDecorator.php, line 14
Namespace
Drupal\language_hierarchyView source
class StringDatabaseStorageDecorator extends StringDatabaseStorage {
use DependencySerializationTrait;
/**
* Core string storage service.
*
* @var \Drupal\locale\StringStorageInterface
*/
protected $stringStorage;
/**
* Language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new StringDatabaseStorage class.
*
* @param \Drupal\locale\StringStorageInterface $string_storage
* Core string storage service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager service.
* @param \Drupal\Core\Database\Connection $connection
* A Database connection to use for reading and writing configuration data.
* @param array $options
* (optional) Any additional database connection options to use in queries.
*/
public function __construct(StringStorageInterface $string_storage, LanguageManagerInterface $language_manager, Connection $connection, array $options = []) {
$this->stringStorage = $string_storage;
$this->languageManager = $language_manager;
parent::__construct($connection, $options);
}
/**
* Performs decorator magic.
*
* @param string $method
* Name of method in the internal service.
* @param array $args
* Arguments to pass to method.
*
* @return mixed
* Returns the results of the method in question.
*/
public function __call($method, array $args) {
return call_user_func_array([
$this->stringStorage,
$method,
], $args);
}
/**
* {@inheritdoc}
*/
protected function dbStringLoad(array $conditions, array $options, $class) {
$strings = parent::dbStringLoad($conditions, $options, $class);
// If querying for a single language, remove fallback results that also
// have corresponding translations in a more specific language.
if (!empty($conditions['language']) && is_scalar($conditions['language'])) {
$filtered = [];
foreach ($strings as $string) {
$lid = $string
->getId();
if (!isset($filtered[$lid])) {
$filtered[$lid] = $string;
}
}
$strings = array_values($filtered);
}
return $strings;
}
/**
* {@inheritdoc}
*/
protected function dbStringSelect(array $conditions, array $options = []) {
$query = $this->stringStorage
->dbStringSelect($conditions, $options);
// The 'translated' meta-condition bypasses fallbacks, since it is used for
// querying specifically for a given language.
if (!isset($conditions['translated'])) {
$tables =& $query
->getTables();
if (isset($tables['t']['arguments'][':langcode'])) {
$attempted_langcode = $tables['t']['arguments'][':langcode'];
// Retrieve the language fallback list.
$candidates = array_values($this->languageManager
->getFallbackCandidates([
'langcode' => $attempted_langcode,
'operation' => 'locale_lookup',
]));
if ($candidates) {
$candidates = array_merge([
$attempted_langcode,
], $candidates);
// Modify langcode to be an array instead of a single value.
$tables['t']['condition'] = "t.lid = s.lid AND t.language IN (:langcode[])";
unset($tables['t']['arguments'][':langcode']);
$tables['t']['arguments'][':langcode[]'] = $candidates;
// Build custom sort criteria.
$query
->addJoin('LEFT', 'language_hierarchy_priority', 'lhp', 't.language = lhp.langcode');
$query
->orderBy('lhp.priority', 'DESC');
}
}
}
return $query;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
StringDatabaseStorage:: |
protected | property | The database connection. | |
StringDatabaseStorage:: |
protected | property | Additional database connection options to use in queries. | |
StringDatabaseStorage:: |
protected | function | Checks whether the string version matches a given version, fix it if not. | |
StringDatabaseStorage:: |
public | function |
Counts source strings. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Counts translations. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Creates a source string object bound to this storage but not saved. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Creates a string translation object bound to this storage but not saved. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
protected | function | Creates delete query. | |
StringDatabaseStorage:: |
protected | function | Executes an arbitrary SELECT query string with the injected options. | |
StringDatabaseStorage:: |
protected | function | Gets table alias for field. | |
StringDatabaseStorage:: |
protected | function | Creates a database record for a string object. | |
StringDatabaseStorage:: |
protected | function | Gets keys values that are in a database table. | |
StringDatabaseStorage:: |
protected | function | Gets table name for storing string object. | |
StringDatabaseStorage:: |
protected | function | Updates string object in the database. | |
StringDatabaseStorage:: |
public | function |
Delete string from storage. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Deletes source strings and translations using conditions. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Deletes translations using conditions. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Loads a string source object, fast query. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Loads a string translation object, fast query. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Loads string location information. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Loads multiple source string objects. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Loads multiple string translation objects. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
public | function |
Save string object to storage. Overrides StringStorageInterface:: |
|
StringDatabaseStorage:: |
protected | function | Update locations for string. | |
StringDatabaseStorageDecorator:: |
protected | property | Language manager service. | |
StringDatabaseStorageDecorator:: |
protected | property | Core string storage service. | |
StringDatabaseStorageDecorator:: |
protected | function |
Loads multiple string objects. Overrides StringDatabaseStorage:: |
|
StringDatabaseStorageDecorator:: |
protected | function |
Builds a SELECT query with multiple conditions and fields. Overrides StringDatabaseStorage:: |
|
StringDatabaseStorageDecorator:: |
public | function | Performs decorator magic. | |
StringDatabaseStorageDecorator:: |
public | function |
Constructs a new StringDatabaseStorage class. Overrides StringDatabaseStorage:: |