TODO: We need a better solution for retrieving webspace paths (the existing
"session manager" is not a good solution).
public getContentPath ( Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior $document ) : string | ||
$document | Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior | |
리턴 | string |
/** * Adds the relative path to the serialization. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $visitor = $event->getVisitor(); $document = $event->getObject(); if (!$document instanceof PathBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor->addData('path', $this->documentInspector->getContentPath($document)); }
/** * {@inheritdoc} */ public function toArray($complete = true) { $document = $this->getDocument(); $result = ['id' => $this->inspector->getUuid($document), 'path' => $this->inspector->getContentPath($document), 'nodeType' => $this->getNodeType(), 'nodeState' => $this->getNodeState(), 'internal' => false, 'concreteLanguages' => $this->inspector->getLocales($document), 'hasSub' => $this->getHasChildren(), 'title' => $document->getTitle()]; if ($document instanceof OrderBehavior) { $result['order'] = $document->getSuluOrder(); } if ($document instanceof RedirectTypeBehavior) { $redirectType = $document->getRedirectType(); $result['linked'] = null; if ($redirectType == RedirectType::INTERNAL && $document->getRedirectTarget() !== null) { $result['linked'] = 'internal'; $result['internal_link'] = $document->getRedirectTarget()->getUuid(); } elseif ($redirectType == RedirectType::EXTERNAL) { $result['linked'] = 'external'; $result['external'] = $document->getRedirectExternal(); } } if ($document instanceof WorkflowStageBehavior) { $result['publishedState'] = $document->getWorkflowStage() === WorkflowStage::PUBLISHED; $result['published'] = $document->getPublished(); } $result['navContexts'] = []; if ($document instanceof NavigationContextBehavior) { $result['navContexts'] = $document->getNavigationContexts(); } if (null !== $this->getType()) { $result['type'] = $this->getType()->toArray(); } if ($complete) { if ($document instanceof ShadowLocaleBehavior) { $result = array_merge($result, ['enabledShadowLanguages' => $this->inspector->getShadowLocales($document), 'shadowOn' => $document->isShadowLocaleEnabled(), 'shadowBaseLanguage' => $document->getShadowLocale() ?: false]); } $result = array_merge($result, ['template' => $this->structure->getName(), 'originTemplate' => $this->structure->getName(), 'creator' => $document->getCreator(), 'changer' => $document->getChanger(), 'created' => $document->getCreated(), 'changed' => $document->getChanged(), 'title' => $document->getTitle(), 'url' => null]); if ($document instanceof ResourceSegmentBehavior) { $result['url'] = $document->getResourceSegment(); } if ($document instanceof ExtensionBehavior) { $result['ext'] = $document->getExtensionsData(); } $result = array_merge($this->getDocument()->getStructure()->toArray(), $result); return $result; } return $result; }
/** * 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); }