/** * Updates the route for the given document after a move or copy. * * @param object $document * @param bool $generateRoutes If set to true a route in the routing tree will also be created */ private function updateRoute($document, $generateRoutes) { $locales = $this->documentInspector->getLocales($document); $webspaceKey = $this->documentInspector->getWebspace($document); $uuid = $this->documentInspector->getUuid($document); $path = $this->documentInspector->getPath($document); $parentUuid = $this->documentInspector->getUuid($this->documentInspector->getParent($document)); $defaultNode = $this->defaultSession->getNode($path); $liveNode = $this->liveSession->getNode($path); $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); foreach ($locales as $locale) { $localizedDocument = $this->documentManager->find($uuid, $locale); if ($localizedDocument->getRedirectType() !== RedirectType::NONE) { continue; } $resourceSegmentPropertyName = $this->encoder->localizedSystemName($this->getResourceSegmentProperty($localizedDocument)->getName(), $locale); $this->updateResourceSegmentProperty($defaultNode, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale); if ($liveNode->hasProperty($resourceSegmentPropertyName)) { $this->updateResourceSegmentProperty($liveNode, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale); // if the method is called with the generateRoutes flag it will create a new route // this happens on a move, but not on copy, because copy results in a draft page without url if ($generateRoutes) { $localizedDocument->setResourceSegment($liveNode->getPropertyValue($resourceSegmentPropertyName)); $resourceLocatorStrategy->save($localizedDocument, null); $localizedDocument->setResourceSegment($defaultNode->getPropertyValue($resourceSegmentPropertyName)); } } } }
/** * Adds the breadcrumb to the serialization. * * @param StructureBehavior $document * @param VisitorInterface $visitor */ private function addBreadcrumb(StructureBehavior $document, VisitorInterface $visitor) { $items = []; $parentDocument = $this->inspector->getParent($document); while ($parentDocument instanceof StructureBehavior) { $item = []; if ($parentDocument instanceof UuidBehavior) { $item['uuid'] = $parentDocument->getUuid(); } $item['title'] = $parentDocument->getStructure()->getProperty('title')->getValue(); $items[] = $item; $parentDocument = $this->inspector->getParent($parentDocument); } $items = array_reverse($items); array_walk($items, function (&$item, $index) { $item['depth'] = $index; }); $visitor->addData('breadcrumb', $items); }
/** * Adjusts the order of the document and its siblings. * * @param ReorderEvent $event */ public function handleReorder(ReorderEvent $event) { $document = $event->getDocument(); if (!$document instanceof OrderBehavior) { return; } $parentDocument = $this->documentInspector->getParent($document); if (null === $parentDocument) { return; } $count = 1; foreach ($this->documentInspector->getChildren($parentDocument) as $childDocument) { if (!$childDocument instanceof OrderBehavior) { continue; } $order = $count * 10; $childDocument->setSuluOrder($order); // TODO move to NodeHelper once integrated in sulu/sulu? $childNode = $this->documentInspector->getNode($childDocument); $childNode->setProperty($this->propertyEncoder->systemName(static::FIELD), $order); ++$count; } }
/** * 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); }
/** * @return $this */ public function getParent() { return $this->documentToStructure($this->inspector->getParent($this->getDocument())); }