Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector::getLocalizedUrlsForPage PHP Method

getLocalizedUrlsForPage() public method

TODO: Implement a router service instead of this.
public getLocalizedUrlsForPage ( BasePageDocument $page ) : array
$page Sulu\Bundle\ContentBundle\Document\BasePageDocument
return array
    public function getLocalizedUrlsForPage(BasePageDocument $page)
    {
        $localizedUrls = [];
        $webspaceKey = $this->getWebspace($page);
        $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
        $node = $this->getNode($page);
        $structure = $this->getStructureMetadata($page);
        $resourceLocatorProperty = $structure->getPropertyByTagName('sulu.rlp');
        foreach ($webspace->getAllLocalizations() as $localization) {
            $resolvedLocale = $localization->getLocalization();
            $locale = $resolvedLocale;
            $shadowEnabledName = $this->encoder->localizedSystemName(ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD, $resolvedLocale);
            if (true === $node->getPropertyValueWithDefault($shadowEnabledName, false)) {
                $shadowLocaleName = $this->encoder->localizedSystemName(ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD, $resolvedLocale);
                $resolvedLocale = $node->getPropertyValue($shadowLocaleName);
            }
            $stageName = $this->encoder->localizedSystemName(WorkflowStageSubscriber::WORKFLOW_STAGE_FIELD, $resolvedLocale);
            if (false === $node->hasProperty($stageName)) {
                continue;
            }
            $stage = $node->getProperty($stageName);
            if (WorkflowStage::PUBLISHED !== $stage->getValue()) {
                continue;
            }
            $url = $node->getPropertyValueWithDefault($this->encoder->localizedContentName($resourceLocatorProperty->getName(), $locale), null);
            if (null === $url) {
                continue;
            }
            $localizedUrls[$locale] = $url;
        }
        return $localizedUrls;
    }

Usage Example

コード例 #1
0
ファイル: ContentMapper.php プロジェクト: kriswillis/sulu
 /**
  * converts a query row to an array.
  */
 private function rowToArray(Row $row, $locale, $webspaceKey, $fields)
 {
     // reset cache
     $this->initializeExtensionCache();
     $templateName = $this->encoder->localizedSystemName('template', $locale);
     $nodeTypeName = $this->encoder->localizedSystemName('nodeType', $locale);
     // check and determine shadow-nodes
     $node = $row->getNode('page');
     $document = $this->documentManager->find($node->getIdentifier(), $locale);
     $originalDocument = $document;
     if (!$node->hasProperty($templateName) && !$node->hasProperty($nodeTypeName)) {
         return false;
     }
     $redirectType = $document->getRedirectType();
     if ($redirectType === RedirectType::INTERNAL) {
         $target = $document->getRedirectTarget();
         if ($target) {
             $url = $target->getResourceSegment();
             $document = $target;
             $node = $this->inspector->getNode($document);
         }
     }
     if ($redirectType === RedirectType::EXTERNAL) {
         $url = 'http://' . $document->getRedirectExternal();
     }
     $originLocale = $locale;
     if ($document instanceof ShadowLocaleBehavior) {
         $locale = $document->isShadowLocaleEnabled() ? $document->getShadowLocale() : $originLocale;
     }
     $nodeState = null;
     if ($document instanceof WorkflowStageBehavior) {
         $nodeState = $document->getWorkflowStage();
     }
     // if page is not piblished ignore it
     if ($nodeState !== WorkflowStage::PUBLISHED) {
         return false;
     }
     if (!isset($url)) {
         $url = $document->getResourceSegment();
     }
     if (false === $url) {
         return;
     }
     // generate field data
     $fieldsData = $this->getFieldsData($row, $node, $document, $fields[$originLocale], $document->getStructureType(), $webspaceKey, $locale);
     $structureType = $document->getStructureType();
     $shortPath = $this->inspector->getContentPath($originalDocument);
     $documentData = array('uuid' => $document->getUuid(), 'nodeType' => $redirectType, 'path' => $shortPath, 'changed' => $document->getChanged(), 'changer' => $document->getChanger(), 'created' => $document->getCreated(), 'published' => $document->getPublished(), 'creator' => $document->getCreator(), 'title' => $originalDocument->getTitle(), 'url' => $url, 'urls' => $this->inspector->getLocalizedUrlsForPage($document), 'locale' => $locale, 'webspaceKey' => $this->inspector->getWebspace($document), 'template' => $structureType, 'parent' => $this->inspector->getParent($document)->getUuid());
     if ($document instanceof OrderBehavior) {
         $documentData['order'] = $document->getSuluOrder();
     }
     return array_merge($documentData, $fieldsData);
 }