/** * Resolve a single result row to a content object. * * @param Row $row * @param string $locale * @param string $locales * @param string $webspaceKey * @param MappingInterface $mapping Includes array of property names. * @param UserInterface $user * * @return Content */ private function resolveContent(Row $row, $locale, $locales, $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() && $row->getValue('internalLink') !== '' && $row->getValue('internalLink') !== $row->getValue('uuid')) { // 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); } $content = 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); $content->setRow($row); if ($mapping->resolveUrl()) { $url = $this->resolveUrl($row, $locale); $urls = []; array_walk($locales, function ($item) use(&$urls, $row) { $urls[$item] = $this->resolveUrl($row, $item); }); $content->setUrl($url); $content->setUrls($urls); } if ($mapping->resolveConcreteLocales()) { $locales = $this->resolveAvailableLocales($row); $content->setConcreteLanguages($locales); } return $content; }
/** * {@inheritdoc} */ public function getType() { $document = $this->getDocument(); $localizationState = $this->inspector->getLocalizationState($document); if ($localizationState === LocalizationState::GHOST) { return StructureType::getGhost($this->getDocument()->getLocale()); } if ($this->inspector->getLocalizationState($document) === LocalizationState::SHADOW) { return StructureType::getShadow($this->getDocument()->getLocale()); } }