getLocale() public method

Return the locale for the given document or null if the document is not managed.
public getLocale ( $document ) : string | null
return string | null
Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * Updates the route for the given document and creates history routes if necessary.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RouteBehavior) {
         return;
     }
     $node = $event->getNode();
     $node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
     $targetDocument = $document->getTargetDocument();
     if ($targetDocument instanceof HomeDocument || !$targetDocument instanceof WebspaceBehavior || !$targetDocument instanceof ResourceSegmentBehavior) {
         return;
     }
     // copy new route to old position
     $webspaceKey = $targetDocument->getWebspaceName();
     $locale = $this->documentInspector->getLocale($document);
     $routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null) . $targetDocument->getResourceSegment();
     // create a route node if it is not a new document and the path changed
     $documentPath = $this->documentInspector->getPath($document);
     if ($documentPath && $documentPath != $routePath) {
         /** @var RouteDocument $newRouteDocument */
         $newRouteDocument = $this->documentManager->create('route');
         $newRouteDocument->setTargetDocument($targetDocument);
         $this->documentManager->persist($newRouteDocument, $locale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($newRouteDocument, $locale);
         // change routes in old position to history
         $this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function getLanguageCode()
 {
     if (!$this->document) {
         return $this->locale;
     }
     return $this->inspector->getLocale($this->getDocument());
 }
Esempio n. 4
0
 /**
  * Copy the routes for all localization of the document in the event.
  *
  * @param CopyEvent $event
  */
 public function updateCopiedDocument(CopyEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ResourceSegmentBehavior) {
         return;
     }
     $this->updateRoute($this->documentManager->find($event->getCopiedPath(), $this->documentInspector->getLocale($document)), false);
 }
Esempio n. 5
0
 /**
  * It shuld lazily initialize a localized property.
  */
 public function testGetLocalizedProperty()
 {
     $name = 'test';
     $contentTypeName = 'hello';
     $locale = 'fr';
     $this->inspector->getLocale($this->document->reveal())->willReturn($locale);
     $this->propertyMetadata->isLocalized()->willReturn(true);
     $this->doGetProperty($name, $contentTypeName, $locale);
 }
Esempio n. 6
0
 /**
  * Invalidates the assigned structure and all urls in the locale of the document when a document gets unpublished.
  * This method is executed before the actual unpublishing of the document because the document must still
  * be published to gather the urls of the document.
  *
  * @param UnpublishEvent $event
  */
 public function invalidateDocumentBeforeUnpublishing(UnpublishEvent $event)
 {
     $document = $event->getDocument();
     if ($document instanceof StructureBehavior) {
         $this->invalidateDocumentStructure($document);
     }
     if ($document instanceof ResourceSegmentBehavior && $document instanceof WorkflowStageBehavior && $document->getPublished()) {
         $this->invalidateDocumentUrls($document, $this->documentInspector->getLocale($document));
     }
 }
Esempio n. 7
0
 /**
  * Adds all the structure specific data (template, structure properties and breadcrumb) to the serialization.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     $context = $event->getContext();
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $visitor = $event->getVisitor();
     $structureMetadata = $this->inspector->getStructureMetadata($document);
     $visitor->addData('template', $document->getStructureType());
     $visitor->addData('originTemplate', $document->getStructureType());
     $visitor->addData('internal', false);
     $visitor->addData('localizedTemplate', $structureMetadata->getTitle($this->inspector->getLocale($document)));
     if (array_search('defaultPage', $context->attributes->get('groups')->getOrElse([])) !== false) {
         $this->addStructureProperties($structureMetadata, $document, $visitor);
     }
     // create bread crumbs
     if (array_search('breadcrumbPage', $context->attributes->get('groups')->getOrElse([])) !== false) {
         $this->addBreadcrumb($document, $visitor);
     }
 }
Esempio n. 8
0
 /**
  * It should persist data from extensions.
  */
 public function testPersistExtensionsData()
 {
     $document = new TestExtensionDocument(['ext_1' => ['foo' => 'bar']]);
     $this->persistEvent->getDocument()->willReturn($document);
     $this->inspector->getWebspace($document)->willReturn('sulu_io');
     $this->inspector->getLocale($document)->shouldBeCalled()->willReturn('de');
     $this->namespaceRegistry->getPrefix('extension_localized')->willReturn('ext_prefix');
     $this->extensionManager->getExtensions('foobar')->willReturn(['ext_1' => $this->extension->reveal()]);
     $this->extension->getName()->willReturn('ext_1');
     $this->extension->setLanguageCode('de', 'ext_prefix', '')->shouldBeCalled();
     $this->extension->save($this->node->reveal(), ['foo' => 'bar'], 'sulu_io', 'de')->shouldBeCalled();
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
 private function hydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     $node = $event->getNode();
     $locale = $this->inspector->getLocale($document);
     $webspaceName = $this->inspector->getWebspace($document);
     $structureType = $document->getStructureType();
     if (null === $structureType) {
         return;
     }
     $prefix = $this->namespaceRegistry->getPrefix('extension_localized');
     $extensionContainer = new ManagedExtensionContainer($structureType, $this->extensionManager, $node, $locale, $prefix, $this->internalPrefix, $webspaceName);
     $document->setExtensionsData($extensionContainer);
 }
Esempio n. 11
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);
 }