Example #1
0
 /**
  * {@inheritdoc}
  */
 public function translateObject($object, $locale)
 {
     $document = $this->documentManager->find($this->inspector->getUuid($object), $locale);
     if ($document instanceof WorkflowStageBehavior && $this->context === SuluKernel::CONTEXT_ADMIN) {
         // set the workflowstage to test, so that the document will be indexed in the index for drafting
         // this change must not be persisted
         // is required because of the expression for the index name uses the workflowstage
         $document->setWorkflowStage(WorkflowStage::TEST);
     }
     return $document;
 }
Example #2
0
 /**
  * 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));
             }
         }
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function save(ResourceSegmentBehavior $document, $userId)
 {
     $path = $document->getResourceSegment();
     $webspaceKey = $this->documentInspector->getWebspace($document);
     $languageCode = $this->documentInspector->getLocale($document);
     try {
         $treeValue = $this->loadByContent($document);
     } catch (ResourceLocatorNotFoundException $e) {
         $treeValue = null;
     }
     if ($treeValue === $path) {
         return false;
     }
     if (!$this->isValid($path, $webspaceKey, $languageCode)) {
         throw new ResourceLocatorNotValidException($path);
     }
     if (!$this->mapper->unique($path, $webspaceKey, $languageCode)) {
         try {
             $treeContent = $this->loadByResourceLocator($path, $webspaceKey, $languageCode);
             // FIXME Required because jackalope-doctrine-dbal does not return references which only exist in the current
             // session. If it would loadByContent would already return some value, which would make this check obsolete.
             if ($treeContent === $this->documentInspector->getUuid($document)) {
                 return false;
             }
             throw new ResourceLocatorAlreadyExistsException($path, $treeContent);
         } catch (ResourceLocatorNotFoundException $exception) {
             // a node exists but is not a resource-locator.
         }
     }
     $this->mapper->save($document);
 }
Example #4
0
 /**
  * {@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;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function loadBreadcrumb($uuid, $locale, $webspaceKey)
 {
     $document = $this->documentManager->find($uuid, $locale);
     $documents = array();
     $contentDocument = $this->getContentDocument($webspaceKey, $locale);
     $contentDepth = $this->inspector->getDepth($contentDocument);
     $document = $this->inspector->getParent($document);
     $documentDepth = $this->inspector->getDepth($document);
     while ($document instanceof StructureBehavior && $documentDepth >= $contentDepth) {
         $documents[] = $document;
         $document = $this->inspector->getParent($document);
         $documentDepth = $this->inspector->getDepth($document);
     }
     $items = array();
     foreach ($documents as $document) {
         $items[] = new BreadcrumbItem($this->inspector->getDepth($document) - $contentDepth, $this->inspector->getUuid($document), $document->getTitle());
     }
     $items = array_reverse($items);
     return $items;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function copyLanguage($uuid, $userId, $webspaceKey, $srcLocale, $destLocales, $structureType = LegacyStructure::TYPE_PAGE)
 {
     if (!is_array($destLocales)) {
         $destLocales = [$destLocales];
     }
     $document = $this->documentManager->find($uuid, $srcLocale);
     $parentDocument = $this->inspector->getParent($document);
     if ($document instanceof ResourceSegmentBehavior) {
         $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey);
     }
     foreach ($destLocales as $destLocale) {
         $destDocument = $this->documentManager->find($uuid, $destLocale);
         $destDocument->setLocale($destLocale);
         $destDocument->getStructure()->bind($document->getStructure()->toArray());
         // TODO: This can be removed if RoutingAuto replaces the ResourceLocator code.
         if ($destDocument instanceof ResourceSegmentBehavior) {
             $resourceLocator = $resourceLocatorStrategy->generate($destDocument->getTitle(), $this->inspector->getUuid($parentDocument), $webspaceKey, $destLocale);
             $destDocument->setResourceSegment($resourceLocator);
         }
         $this->documentManager->persist($destDocument, $destLocale);
     }
     $this->documentManager->flush();
     return $this->documentToStructure($document);
 }