Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function getProperty($name)
 {
     $this->init();
     if (isset($this->properties[$name])) {
         return $this->properties[$name];
     }
     if (!$this->node) {
         $this->node = $this->inspector->getNode($this->document);
     }
     $structureProperty = $this->structureMetadata->getProperty($name);
     $contentTypeName = $structureProperty->getType();
     $bridge = new StructureBridge($this->structureMetadata, $this->inspector, $this->legacyPropertyFactory, $this->document);
     if ($structureProperty->isLocalized()) {
         $locale = $this->inspector->getLocale($this->document);
         $property = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale, $bridge);
     } else {
         $property = $this->legacyPropertyFactory->createProperty($structureProperty);
     }
     $this->legacyProperties[$name] = $property;
     $property->setStructure($bridge);
     $contentType = $this->contentTypeManager->get($contentTypeName);
     $contentType->read($this->node, $property, null, null, null);
     $valueProperty = new PropertyValue($name, $property->getValue());
     $this->properties[$name] = $valueProperty;
     return $valueProperty;
 }
 private function validateShadow(ShadowLocaleBehavior $document)
 {
     if ($document->getLocale() === $document->getShadowLocale()) {
         throw new \RuntimeException(sprintf('Document cannot be a shadow of itself for locale "%s"', $document->getLocale()));
     }
     $locales = $this->inspector->getConcreteLocales($document);
     if (!in_array($document->getShadowLocale(), $locales)) {
         $this->inspector->getNode($document)->revert();
         throw new \RuntimeException(sprintf('Attempting to create shadow for "%s" on a non-concrete locale "%s" for document at "%s". Concrete languages are "%s"', $document->getLocale(), $document->getShadowLocale(), $this->inspector->getPath($document), implode('", "', $locales)));
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function save(ResourceSegmentBehavior $document)
 {
     $path = $document->getResourceSegment();
     $webspaceKey = $this->documentInspector->getWebspace($document);
     $locale = $this->documentInspector->getLocale($document);
     $segmentKey = null;
     $webspaceRouteRootPath = $this->getWebspaceRouteNodeBasePath($webspaceKey, $locale, $segmentKey);
     try {
         $routeNodePath = $this->loadByContent($this->documentInspector->getNode($document), $webspaceKey, $locale, $segmentKey);
         $routeDocument = $this->documentManager->find($webspaceRouteRootPath . $routeNodePath, $locale, ['rehydrate' => false]);
         $routeDocumentPath = $webspaceRouteRootPath . $routeNodePath;
     } catch (ResourceLocatorNotFoundException $e) {
         $routeDocument = $this->documentManager->create('route');
         $routeDocumentPath = $webspaceRouteRootPath . $path;
     }
     $routeDocument->setTargetDocument($document);
     try {
         $this->documentManager->persist($routeDocument, $locale, ['path' => $routeDocumentPath, 'auto_create' => true, 'override' => true]);
         $this->documentManager->publish($routeDocument, $locale);
     } catch (ItemExistsException $e) {
         throw new ResourceLocatorAlreadyExistsException($document->getResourceSegment(), $routeDocumentPath);
     }
 }
Beispiel #4
0
 /**
  * Changes the old route to a history route and redirect to the new route.
  *
  * @param RouteBehavior $oldDocument
  * @param RouteBehavior $newDocument
  */
 private function changeOldPathToHistoryRoutes(RouteBehavior $oldDocument, RouteBehavior $newDocument)
 {
     $oldDocument->setTargetDocument($newDocument);
     $oldDocument->setHistory(true);
     $oldRouteNode = $this->documentInspector->getNode($oldDocument);
     $oldRouteNode->setProperty(self::NODE_HISTORY_FIELD, true);
     foreach ($this->documentInspector->getReferrers($oldDocument) as $referrer) {
         if ($referrer instanceof RouteBehavior) {
             $referrer->setTargetDocument($newDocument);
             $referrer->setHistory(true);
             $this->documentManager->persist($referrer, null, ['path' => $this->documentInspector->getPath($referrer)]);
             $this->documentManager->publish($referrer, null);
         }
     }
 }
 public function setUp()
 {
     $this->contentTypeManager = $this->prophesize(ContentTypeManagerInterface::class);
     $this->node = $this->prophesize(NodeInterface::class);
     $this->structureMetadata = $this->prophesize(StructureMetadata::class);
     $this->document = $this->prophesize(StructureBehavior::class);
     $this->contentType = $this->prophesize(ContentTypeInterface::class);
     $this->encoder = $this->prophesize(PropertyEncoder::class);
     $this->propertyMetadata = $this->prophesize(PropertyMetadata::class);
     $this->propertyFactory = $this->prophesize(LegacyPropertyFactory::class);
     $this->inspector = $this->prophesize(DocumentInspector::class);
     $this->legacyProperty = $this->prophesize(PropertyInterface::class);
     $this->structure = new ManagedStructure($this->contentTypeManager->reveal(), $this->propertyFactory->reveal(), $this->inspector->reveal(), $this->document->reveal());
     $this->inspector->getNode($this->document->reveal())->willReturn($this->node->reveal());
     $this->inspector->getStructureMetadata($this->document->reveal())->willReturn($this->structureMetadata->reveal());
 }
Beispiel #6
0
 /**
  * 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;
     }
 }
Beispiel #7
0
 /**
  * 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);
 }
 private function getEvent($document)
 {
     $webspace = $this->inspector->getWebspace($document);
     $event = new ContentNodeDeleteEvent($this->mapper, $this->nodeHelper, $this->inspector->getNode($document), $webspace);
     return $event;
 }
Beispiel #9
0
 /**
  * {@inheritdoc}
  */
 public function loadByContent(ResourceSegmentBehavior $document)
 {
     // delegate to mapper
     return $this->mapper->loadByContent($this->documentInspector->getNode($document), $this->documentInspector->getWebspace($document), $this->documentInspector->getLocale($document), null);
 }