Exemplo n.º 1
0
 /**
  * @param AbstractMappingEvent $event
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     $node = $event->getNode();
     $property = $this->getResourceSegmentProperty($document);
     $originalLocale = $this->inspector->getOriginalLocale($document);
     $segment = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName($property->getName(), $originalLocale), '');
     $document->setResourceSegment($segment);
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof TimestampBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $accessor = $event->getAccessor();
     $accessor->set(self::CREATED, $node->getPropertyValueWithDefault($v = $this->encoder->localizedSystemName(self::CREATED, $locale), null));
     $accessor->set(self::CHANGED, $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CHANGED, $locale), null));
 }
Exemplo n.º 3
0
 /**
  * Sets the title on the node from the value in the document.
  *
  * @param PersistEvent $event
  */
 public function setTitleOnNode(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     if ($document instanceof LocalizedTitleBehavior) {
         if (!$event->getLocale()) {
             return;
         }
         $event->getNode()->setProperty($this->propertyEncoder->localizedContentName(static::PROPERTY_NAME, $event->getLocale()), $document->getTitle());
     } else {
         $event->getNode()->setProperty($this->propertyEncoder->contentName(static::PROPERTY_NAME), $document->getTitle());
     }
 }
Exemplo n.º 4
0
 /**
  * Append mapping selects for a single property to given query-builder.
  *
  * @param QueryBuilder $queryBuilder
  * @param string $propertyName
  * @param string[] $locales
  */
 private function appendSingleMapping(QueryBuilder $queryBuilder, $propertyName, $locales)
 {
     foreach ($locales as $locale) {
         $alias = sprintf('%s%s', $locale, str_replace('-', '_', ucfirst($propertyName)));
         $queryBuilder->addSelect('node', $this->propertyEncoder->localizedContentName($propertyName, $locale), $alias);
     }
 }
Exemplo n.º 5
0
 /**
  * Sets the workflow stage properties on the given node.
  *
  * @param NodeInterface $node
  * @param string $locale
  * @param int $workflowStage
  * @param bool $updatePublished
  */
 private function setWorkflowStageOnNode(NodeInterface $node, $locale, $workflowStage, $updatePublished)
 {
     $node->setProperty($this->propertyEncoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, $locale), $workflowStage);
     if ($updatePublished) {
         $node->setProperty($this->propertyEncoder->localizedSystemName(self::PUBLISHED_FIELD, $locale), new \DateTime());
     }
 }
Exemplo n.º 6
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));
             }
         }
     }
 }
Exemplo n.º 7
0
 private function getStructureTypePropertyName($document, $locale)
 {
     if ($document instanceof LocalizedStructureBehavior) {
         return $this->encoder->localizedSystemName(self::STRUCTURE_TYPE_FIELD, $locale);
     }
     // TODO: This is the wrong namespace, it should be the system namespcae, but we do this for initial BC
     return $this->encoder->contentName(self::STRUCTURE_TYPE_FIELD);
 }
Exemplo n.º 8
0
 /**
  * Adds the order to the document.
  *
  * @param AbstractMappingEvent $event
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     if (false == $this->supports($event->getDocument())) {
         return;
     }
     $node = $event->getNode();
     $order = $node->getPropertyValueWithDefault($this->encoder->systemName(self::FIELD), null);
     $event->getAccessor()->set('suluOrder', $order);
 }
Exemplo n.º 9
0
 private function getWorkflowStage(NodeInterface $node, $locale)
 {
     $value = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, $locale), null);
     return $value;
 }
Exemplo n.º 10
0
 /**
  * @param NamespaceRegistry $namespaceRegistry
  */
 public function __construct(NamespaceRegistry $namespaceRegistry)
 {
     parent::__construct($namespaceRegistry);
 }
Exemplo n.º 11
0
 private function getCreator(NodeInterface $node, $locale)
 {
     return $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CREATOR, $locale), null);
 }