public function StringMongoDBStorage::findTranslation in MongoDB 8
Loads a string translation object, fast query.
This function must only be used when actually translating strings as it will have the effect of updating the string version. For other purposes the getTranslations() method should be used instead.
Parameters
array $conditions: (optional) Array with conditions that will be used to filter the strings returned and may include all of the conditions defined by getStrings().
Return value
\Drupal\locale\TranslationString|null Minimal TranslationString object if found, NULL otherwise.
Overrides StringStorageInterface::findTranslation
File
- mongodb_locale/
src/ StringStorage.php, line 175
Class
Namespace
Drupal\mongodb_localeCode
public function findTranslation(array $conditions) {
$language = $conditions['language'];
$find = array();
$find['translations.language'] = $language;
if (isset($conditions['lid'])) {
$find += $this
->getIdCriteria($conditions['lid']);
}
if (isset($conditions['context'])) {
$find['context'] = $conditions['context'];
}
$values = $this->mongo
->get('locale')
->findOne($find, array(
'source' => TRUE,
'context' => TRUE,
'version' => TRUE,
'translations.$' => TRUE,
));
if ($values) {
$values['lid'] = (string) $values['_id'];
// $values['translations'][0] contains the right translation courtesy of
// the translations.$ projection operator.
$values['translation'] = $values['translations'][0]['translation'];
$values['customized'] = $values['translations'][0]['customized'];
unset($values['translations'], $values['_id']);
$string = new TranslationString($values);
$this
->checkVersion($string, \Drupal::VERSION);
return $string
->setStorage($this);
}
}