Doctrine\ODM\PHPCR\UnitOfWork::doLoadDatabaseTranslation PHP Метод

doLoadDatabaseTranslation() защищенный Метод

If $fallback is true, goes over the locales as provided by the locale chooser strategy to find the best language, each time first checking for a pending translation. If no translation is found at all, the translated fields are set to null and the requested locale is considered to be the one found.
См. также: doLoadTranslation
protected doLoadDatabaseTranslation ( object $document, ClassMetadata $metadata, string $locale, boolean $fallback, boolean $refresh ) : string
$document object
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$locale string The desired locale.
$fallback boolean Whether to perform language fallback.
$refresh boolean Whether to force reloading the translation.
Результат string The locale used
    protected function doLoadDatabaseTranslation($document, ClassMetadata $metadata, $locale, $fallback, $refresh)
    {
        $oid = spl_object_hash($document);
        $strategy = $this->dm->getTranslationStrategy($metadata->translator);
        try {
            $node = $this->session->getNode($this->getDocumentId($oid));
            if ($strategy->loadTranslation($document, $node, $metadata, $locale)) {
                return $locale;
            }
        } catch (PathNotFoundException $e) {
            // no node, document not persisted yet
            $node = null;
        }
        if (!$fallback) {
            $msg = sprintf('Document %s has no translation %s and fallback was not active', $this->getDocumentId($oid), $locale);
            throw new MissingTranslationException($msg);
        }
        $localesToTry = $this->dm->getLocaleChooserStrategy()->getFallbackLocales($document, $metadata, $locale);
        foreach ($localesToTry as $desiredLocale) {
            if (!$refresh && isset($this->documentLocales[$oid]['current']) && $desiredLocale == $this->documentLocales[$oid]['current']) {
                // noop, already the correct locale.
                return $desiredLocale;
            }
            // if there is a pending translation, it wins
            if ($this->doLoadPendingTranslation($document, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
            // try loading the translation with strategy if this is a stored document
            if ($node && $strategy->loadTranslation($document, $node, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
        }
        // we found no locale. so all translated fields are null and we
        // consider the locale to be the requested one
        $localeUsed = $locale;
        foreach ($metadata->translatableFields as $fieldName) {
            $value = $metadata->mappings[$fieldName]['multivalue'] ? array() : null;
            $metadata->reflFields[$fieldName]->setValue($document, $value);
        }
        return $locale;
    }
UnitOfWork