/** * Return all structures (i.e. for for each language). * * @return Sulu\Component\Content\MetadataInterface[] */ public function getStructures() { $structures = []; foreach ($this->nodeHelper->getLanguagesForNode($this->node) as $locale) { $structures[] = $this->getStructure($locale); } return $structures; }
/** * 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); }
/** * adopts resource locator of children by iteration. * * @param NodeInterface $contentNode * @param int $userId * @param string $webspaceKey * @param string $languageCode * @param bool $iterate * @param string $segmentKey */ private function adaptResourceLocators(NodeInterface $contentNode, $userId, $webspaceKey, $languageCode, $segmentKey = null, $iterate = true) { foreach ($contentNode->getNodes() as $node) { // determine structure $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode); if (!$node->hasProperty($templatePropertyName)) { continue; } $template = $node->getPropertyValue($templatePropertyName); $structure = $this->structureManager->getStructure($template); // only if rlp exists if ($structure->hasTag('sulu.rlp')) { // get rlp try { $rlp = $this->loadByContent($node, $webspaceKey, $languageCode); } catch (ResourceLocatorNotFoundException $ex) { $contentNode->getSession()->save(); $rlpPart = $node->getPropertyValue($this->nodeHelper->getTranslatedPropertyName('title', $languageCode)); $prentRlp = $this->mapper->getParentPath($node->getIdentifier(), $webspaceKey, $languageCode, $segmentKey); // generate new resourcelocator $rlp = $this->generate($rlpPart, $prentRlp, $webspaceKey, $languageCode); } // determine rlp property $property = $structure->getPropertyByTagName('sulu.rlp'); $contentType = $this->contentTypeManager->get($property->getContentTypeName()); $property->setValue($rlp); // write value to node $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode); $contentType->write($node, $translatedProperty, $userId, $webspaceKey, $languageCode, $segmentKey); } // for node move the tree will be copied to then there is the iteration over this function // for node copy the iteration is done by the content-type which calls over the move function // recursively this function if ($iterate) { $this->adaptResourceLocators($node, $userId, $webspaceKey, $languageCode, $segmentKey); } } }