/** * @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)); }
/** * 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()); } }
/** * 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)); } } } }
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); }
/** * Append mapping selects to given query-builder. * * @param QueryBuilder $queryBuilder * @param MappingInterface $mapping Includes array of property names. * @param string $locale * @param string[] $locales */ private function appendMapping(QueryBuilder $queryBuilder, MappingInterface $mapping, $locale, $locales) { if ($mapping->onlyPublished()) { $queryBuilder->andWhere($this->qomFactory->comparison($this->qomFactory->propertyValue('node', $this->propertyEncoder->localizedSystemName('state', $locale)), '=', $this->qomFactory->literal(WorkflowStage::PUBLISHED))); } $properties = $mapping->getProperties(); foreach ($properties as $propertyName) { $this->appendSingleMapping($queryBuilder, $propertyName, $locales); } if ($mapping->resolveUrl()) { $this->appendUrlMapping($queryBuilder, $locales); } }
private function getWorkflowStage(NodeInterface $node, $locale) { $value = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, $locale), null); return $value; }
private function getCreator(NodeInterface $node, $locale) { return $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CREATOR, $locale), null); }