/**
* 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);
}