Returns structure for given key and type.
public getStructure ( string $key, string $type = Structure::TYPE_PAGE ) : Sulu\Component\Content\Compat\StructureInterface | ||
$key | string | |
$type | string | |
return | Sulu\Component\Content\Compat\StructureInterface |
/** * {@inheritdoc} */ public function generate($parts, $parentUuid, $webspaceKey, $languageCode, $templateKey, $segmentKey = null) { /** @var StructureInterface $structure */ $structure = $this->structureManager->getStructure($templateKey); $title = $this->implodeRlpParts($structure, $parts); $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); $resourceLocator = $resourceLocatorStrategy->generate($title, $parentUuid, $webspaceKey, $languageCode, $segmentKey); return ['resourceLocator' => $resourceLocator, '_links' => ['self' => $this->getBasePath() . '/generates']]; }
/** * {@inheritdoc} */ public function getStructures($webspaceKey) { if (!$this->cache->contains($webspaceKey)) { return $this->loadStructures($webspaceKey); } $keys = $this->cache->fetch($webspaceKey); return array_map(function ($key) { return $this->structureManager->getStructure($key); }, $keys); }
/** * {@inheritdoc} */ public function generate($parts, $parentUuid, $uuid, $webspaceKey, $languageCode, $templateKey, $segmentKey = null) { /** @var StructureInterface $structure */ $structure = $this->structureManager->getStructure($templateKey); $title = $this->implodeRlpParts($structure, $parts); if ($parentUuid !== null) { $parentPath = $this->strategy->loadByContentUuid($parentUuid, $webspaceKey, $languageCode, $segmentKey); $result = $this->strategy->generate($title, $parentPath, $webspaceKey, $languageCode, $segmentKey); } elseif ($uuid !== null) { $result = $this->strategy->generateForUuid($title, $uuid, $webspaceKey, $languageCode, $segmentKey); } else { $parentPath = '/'; $result = $this->strategy->generate($title, $parentPath, $webspaceKey, $languageCode, $segmentKey); } return ['resourceLocator' => $result, '_links' => ['self' => $this->getBasePath() . '/generates']]; }
/** * Returns and caches excerpt-structure. * * @return StructureInterface */ private function getExcerptStructure() { if ($this->excerptStructure === null) { $this->excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME); $this->excerptStructure->setLanguageCode($this->languageCode); } return $this->excerptStructure; }
/** * Returns a select statement for excerpt data. */ private function buildSelectorForExcerpt($locale, &$additionalFields) { $excerptStructure = $this->structureManager->getStructure('excerpt'); $extension = $this->structureManager->getExtension('', 'excerpt'); foreach ($excerptStructure->getProperties(true) as $property) { $additionalFields[$locale][] = ['extension' => $extension, 'target' => 'excerpt', 'property' => $property->getName(), 'name' => $property->getName()]; } }
/** * {@inheritdoc} */ public function updateTemplate($template, $userId, $contentUuid, $webspaceKey, $locale) { /** @var PageBridge $structure */ $structure = $this->fetchStructure($userId, $contentUuid, $webspaceKey, $locale); /** @var PageBridge $newStructure */ $newStructure = $this->structureManager->getStructure($template); $newStructure->copyFrom($structure); $this->saveStructure($newStructure, $userId, $contentUuid, $webspaceKey, $locale); }
/** * Resolve url property. * * @param Row $row * @param string $locale * * @return string */ private function resolveUrl(Row $row, $locale) { if ($this->resolveProperty($row, $locale . 'State', $locale) !== WorkflowStage::PUBLISHED) { return; } $template = $this->resolveProperty($row, 'template', $locale); if (empty($template)) { return; } $structure = $this->structureManager->getStructure($template); if (!$structure->hasTag('sulu.rlp')) { return; } $propertyName = $structure->getPropertyByTagName('sulu.rlp')->getName(); return $this->resolveProperty($row, $propertyName, $locale); }
/** * Loops all documents and imports all properties of the documents. * * @param BasePageDocument $document * @param string $structureType * @param string $webspaceKey * @param string $locale * @param string $format * @param array $data */ protected function setDocumentData(BasePageDocument $document, $structureType, $webspaceKey, $locale, $format, $data) { $structure = $this->structureManager->getStructure($structureType); $properties = $structure->getProperties(true); $node = $this->documentRegistry->getNodeForDocument($document); $node->setProperty(sprintf('i18n:%s-template', $locale), $structureType); $state = $this->getParser($format)->getPropertyData('state', $data, null, null, 2); $node->setProperty(sprintf('i18n:%s-state', $locale), $state); if ($this->getParser($format)->getPropertyData('title', $data) === '') { $this->addException(sprintf('Document(%s) has not set any title', $document->getUuid()), 'ignore'); return false; } // import all content data foreach ($properties as $property) { $value = $this->getParser($format)->getPropertyData($property->getName(), $data, $property->getContentTypeName()); // don't generate a new url when one exists $doImport = true; if ($property->getContentTypeName() == 'resource_locator') { $doImport = false; if (!$document->getResourceSegment()) { $doImport = true; $parent = $document->getParent(); if ($parent instanceof BasePageDocument) { $parentUuid = $parent->getUuid(); $value = $this->generateUrl($structure->getPropertiesByTagName('sulu.rlp.part'), $parentUuid, $webspaceKey, $locale, $format, $data); } } } // import property data if ($doImport) { $this->importProperty($property, $node, $structure, $value, $webspaceKey, $locale, $format); } } // import extensions $extensions = $this->extensionManager->getExtensions($structureType); foreach ($extensions as $key => $extension) { $this->importExtension($extension, $key, $node, $data, $webspaceKey, $locale, $format); } // set required data $document->setTitle($this->getParser($format)->getPropertyData('title', $data)); return true; }
/** * 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); } } }
/** * initiates structure and properties. */ private function initExcerptStructure() { $excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME); /** @var PropertyInterface $property */ foreach ($excerptStructure->getProperties() as $property) { $this->properties[] = $property->getName(); } return $excerptStructure; }