getWebspace() public method

Return the webspace name for the given document.
public getWebspace ( object $document ) : string
$document object
return string
示例#1
0
 public function testHandleWebspace()
 {
     $document = $this->prophesize(WebspaceBehavior::class);
     $this->persistEvent->getDocument()->willReturn($document);
     $this->inspector->getWebspace($document->reveal())->willReturn('example');
     $this->accessor->set('webspaceName', 'example')->shouldBeCalled();
     $this->subscriber->handleWebspace($this->persistEvent->reveal());
 }
示例#2
0
 /**
  * @param AbstractMappingEvent $event
  */
 public function handleWebspace(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof WebspaceBehavior) {
         return;
     }
     $webspaceName = $this->inspector->getWebspace($document);
     $event->getAccessor()->set('webspaceName', $webspaceName);
 }
示例#3
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));
             }
         }
     }
 }
示例#4
0
 /**
  * Set routes to custom-url.
  *
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof CustomUrlBehavior) {
         return;
     }
     $webspaceKey = $this->inspector->getWebspace($document);
     $document->setRoutes($this->findReferrer($document, $webspaceKey));
 }
 /**
  * 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());
 }
示例#6
0
文件: PhpcrMapper.php 项目: sulu/sulu
 /**
  * {@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);
     }
 }
示例#7
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);
 }
 /**
  * It should return any localizations if neither parent nor children.
  */
 public function testWebspaceAnyLocalization()
 {
     $this->inspector->getWebspace($this->document->reveal())->willReturn(self::FIX_WEBSPACE);
     $this->inspector->getLocales($this->document->reveal())->willReturn(['de']);
     $this->webspace->getLocalization(self::FIX_LOCALE)->willReturn($this->localization1->reveal());
     $this->localization1->getLocalization()->willReturn('en');
     $this->localization2->getLocalization()->willReturn('de');
     $this->hydrateEvent->getOption('load_ghost_content', true)->willReturn(true);
     $this->localization1->getParent()->willReturn(null);
     $this->localization1->getChildren()->willReturn([]);
     $this->webspace->getLocalizations()->willReturn([$this->localization2->reveal()]);
     $this->registry->updateLocale($this->document->reveal(), 'de', 'en')->shouldBeCalled();
     $this->hydrateEvent->setLocale('de')->shouldBeCalled();
     $this->subscriber->handleHydrate($this->hydrateEvent->reveal());
 }
示例#9
0
 private function doGetProperty($name, $contentTypeName, $locale)
 {
     $this->propertyMetadata->getType()->willReturn($contentTypeName);
     $this->structureMetadata->getProperty($name)->willReturn($this->propertyMetadata);
     $this->contentTypeManager->get($contentTypeName)->willReturn($this->contentType->reveal());
     if ($locale) {
         $this->propertyFactory->createTranslatedProperty($this->propertyMetadata->reveal(), $locale, Argument::type(StructureBridge::class))->willReturn($this->legacyProperty->reveal());
     } else {
         $this->propertyFactory->createProperty($this->propertyMetadata->reveal(), $locale)->willReturn($this->legacyProperty->reveal());
     }
     $this->inspector->getWebspace($this->document->reveal())->willReturn('sulu_io');
     $this->inspector->getOriginalLocale($this->document->reveal())->willReturn($locale);
     $this->contentType->read($this->node->reveal(), $this->legacyProperty->reveal(), 'sulu_io', $locale, null)->shouldBeCalledTimes(1);
     $property = $this->structure->getProperty($name);
     $this->assertInstanceOf(PropertyValue::class, $property);
     $this->assertEquals($name, $property->getName());
 }
示例#10
0
 /**
  * It should throw an exception if the property is required but the value is null.
  *
  * @expectedException Sulu\Component\Content\Exception\MandatoryPropertyException
  */
 public function testThrowExceptionPropertyRequired()
 {
     $document = new TestContentDocument($this->structure->reveal());
     $document->setStructureType('foobar');
     $this->persistEvent->getDocument()->willReturn($document);
     // map the structure type
     $this->persistEvent->getLocale()->willReturn('fr');
     // map the content
     $this->inspector->getStructureMetadata($document)->willReturn($this->structureMetadata->reveal());
     $this->inspector->getWebspace($document)->willReturn('webspace');
     $this->structureMetadata->getProperties()->willReturn(['prop1' => $this->structureProperty->reveal()]);
     $this->structureProperty->isRequired()->willReturn(true);
     $this->structure->getProperty('prop1')->willReturn($this->propertyValue->reveal());
     $this->propertyValue->getValue()->willReturn(null);
     $this->structureMetadata->getName()->willReturn('test');
     $this->structureMetadata->getResource()->willReturn('/path/to/resource.xml');
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
 /**
  * Return available localizations.
  *
  * @param StructureBehavior $document
  * @param string            $locale
  *
  * @return string
  */
 public function getAvailableLocalization(StructureBehavior $document, $locale)
 {
     $availableLocales = $this->inspector->getLocales($document);
     if (in_array($locale, $availableLocales)) {
         return $locale;
     }
     $fallbackLocale = null;
     if ($document instanceof WebspaceBehavior) {
         $fallbackLocale = $this->localizationFinder->findAvailableLocale($this->inspector->getWebspace($document), $availableLocales, $locale);
     }
     if (!$fallbackLocale) {
         $fallbackLocale = reset($availableLocales);
     }
     if (!$fallbackLocale) {
         $fallbackLocale = $this->documentRegistry->getDefaultLocale();
     }
     return $fallbackLocale;
 }
示例#12
0
 /**
  * Map to the content properties to the node using the content types.
  *
  * @param mixed $document
  * @param NodeInterface $node
  * @param string $locale
  *
  * @throws MandatoryPropertyException
  */
 private function mapContentToNode($document, NodeInterface $node, $locale)
 {
     $structure = $document->getStructure();
     $webspaceName = $this->inspector->getWebspace($document);
     $metadata = $this->inspector->getStructureMetadata($document);
     foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
         $realProperty = $structure->getProperty($propertyName);
         $value = $realProperty->getValue();
         if ($structureProperty->isRequired() && null === $value) {
             throw new MandatoryPropertyException(sprintf('Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"', $propertyName, $metadata->getName(), $metadata->resource));
         }
         $contentTypeName = $structureProperty->getContentTypeName();
         $contentType = $this->contentTypeManager->get($contentTypeName);
         // TODO: Only write if the property has been modified.
         $legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
         $legacyProperty->setValue($value);
         $contentType->remove($node, $legacyProperty, $webspaceName, $locale, null);
         $contentType->write($node, $legacyProperty, null, $webspaceName, $locale, null);
     }
 }
示例#13
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);
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 public function getWebspaceKey()
 {
     return $this->inspector->getWebspace($this->getDocument());
 }
示例#15
0
 private function getEvent($document)
 {
     $webspace = $this->inspector->getWebspace($document);
     $event = new ContentNodeDeleteEvent($this->mapper, $this->nodeHelper, $this->inspector->getNode($document), $webspace);
     return $event;
 }
示例#16
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);
 }