/** * Resolve a single result row to a content object. * * @param Row $row * @param string $locale * @param string $webspaceKey * @param MappingInterface $mapping Includes array of property names. * @param UserInterface $user * * @return Content */ private function resolveContent(Row $row, $locale, $webspaceKey, MappingInterface $mapping, UserInterface $user = null) { if (!$webspaceKey) { $webspaceKey = $this->nodeHelper->extractWebspaceFromPath($row->getPath()); } $originalLocale = $locale; $ghostLocale = $this->localizationFinder->findAvailableLocale($webspaceKey, $this->resolveAvailableLocales($row), $locale); $type = null; if ($row->getValue('shadowOn')) { if (!$mapping->shouldHydrateShadow()) { return; } $type = StructureType::getShadow($row->getValue('shadowBase')); } elseif ($ghostLocale !== $originalLocale) { if (!$mapping->shouldHydrateGhost()) { return; } $locale = $ghostLocale; $type = StructureType::getGhost($locale); } if ($row->getValue('nodeType') === RedirectType::INTERNAL && $mapping->followInternalLink()) { // TODO collect all internal link contents and query once return $this->resolveInternalLinkContent($row, $locale, $webspaceKey, $mapping, $type, $user); } $shadowBase = null; if ($row->getValue('shadowOn')) { $shadowBase = $row->getValue('shadowBase'); } $data = []; foreach ($mapping->getProperties() as $item) { $data[$item] = $this->resolveProperty($row, $item, $locale, $shadowBase); } return new Content($locale, $webspaceKey, $row->getValue('uuid'), $this->resolvePath($row, $webspaceKey), $row->getValue('state'), $row->getValue('nodeType'), $this->resolveHasChildren($row), $data, $this->resolvePermissions($row, $user), $type); }
/** * Return available localizations. * * @param StructureBehavior $document * @param string $locale * * @return string */ public function getAvailableLocalization(StructureBehavior $document, $locale) { $availableLocales = $this->inspector->getLocales($document); if (in_array($locale, $availableLocales)) { return $locale; } $fallbackLocale = null; if ($document instanceof WebspaceBehavior) { $fallbackLocale = $this->localizationFinder->findAvailableLocale($this->inspector->getWebspace($document), $availableLocales, $locale); } if (!$fallbackLocale) { $fallbackLocale = reset($availableLocales); } if (!$fallbackLocale) { $fallbackLocale = $this->documentRegistry->getDefaultLocale(); } return $fallbackLocale; }