コード例 #1
0
 /**
  * @param AbstractMappingEvent $event
  *
  * @throws DocumentManagerException
  */
 public function handleLocale(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof LocaleBehavior) {
         return;
     }
     $event->getAccessor()->set('locale', $this->registry->getLocaleForDocument($document));
 }
コード例 #2
0
ファイル: ShadowLocaleSubscriber.php プロジェクト: sulu/sulu
 /**
  * Adds the enabled shadow languages to the serialization.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     if (!$document instanceof ShadowLocaleBehavior || !$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $visitor = $event->getVisitor();
     $visitor->addData('enabledShadowLanguages', $this->documentInspector->getShadowLocales($document));
 }
コード例 #3
0
ファイル: PathSubscriber.php プロジェクト: sulu/sulu
 /**
  * Adds the relative path to the serialization.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $visitor = $event->getVisitor();
     $document = $event->getObject();
     if (!$document instanceof PathBehavior || !$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $visitor->addData('path', $this->documentInspector->getContentPath($document));
 }
コード例 #4
0
ファイル: ChildrenSubscriber.php プロジェクト: sulu/sulu
 /**
  * Adds a flag to indicate if the document has children.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     if (!$document instanceof ChildrenBehavior || !$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $visitor = $event->getVisitor();
     $visitor->addData('hasSub', $this->documentInspector->hasChildren($document));
 }
コード例 #5
0
 /**
  * @param RefreshEvent $event
  */
 public function handleRefresh(RefreshEvent $event)
 {
     $document = $event->getDocument();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $locale = $this->documentRegistry->getLocaleForDocument($document);
     // revert/reload the node to the persisted state
     $node->revert();
     // rehydrate the document
     $hydrateEvent = new HydrateEvent($node, $locale);
     $hydrateEvent->setDocument($document);
     $this->eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
 }
コード例 #6
0
ファイル: DefaultSnippetManager.php プロジェクト: sulu/sulu
 /**
  * {@inheritdoc}
  */
 public function save($webspaceKey, $type, $uuid, $locale)
 {
     /** @var SnippetDocument $document */
     $document = $this->documentManager->find($uuid, $locale);
     if (!$document) {
         throw new SnippetNotFoundException($uuid);
     }
     if ($document->getStructureType() !== $type) {
         throw new WrongSnippetTypeException($document->getStructureType(), $type, $document);
     }
     $this->settingsManager->save($webspaceKey, 'snippets-' . $type, $this->registry->getNodeForDocument($document));
     return $document;
 }
コード例 #7
0
 /**
  * Handle the reorder operation.
  *
  * @param ReorderEvent $event
  *
  * @throws DocumentManagerException
  */
 public function handleReorder(ReorderEvent $event)
 {
     $document = $event->getDocument();
     $siblingId = $event->getDestId();
     $after = $event->getAfter();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $parentNode = $node->getParent();
     $nodeName = $node->getName();
     $siblingName = $this->resolveSiblingName($siblingId, $parentNode, $node);
     if (true === $after) {
         $siblingName = $this->resolveAfterSiblingName($parentNode, $siblingName);
     }
     $parentNode->orderBefore($nodeName, $siblingName);
 }
コード例 #8
0
ファイル: LocaleSubscriber.php プロジェクト: sulu/sulu
 /**
  * Adds the concrete languages available and the type (ghost or shadow) of the document to the serialization.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     if (!$document instanceof LocaleBehavior || !$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $visitor = $event->getVisitor();
     $visitor->addData('concreteLanguages', $this->documentInspector->getConcreteLocales($document));
     $localizationState = $this->documentInspector->getLocalizationState($document);
     if ($localizationState === LocalizationState::GHOST) {
         $visitor->addData('type', ['name' => 'ghost', 'value' => $document->getLocale()]);
     }
     if ($localizationState === LocalizationState::SHADOW) {
         $visitor->addData('type', ['name' => 'shadow', 'value' => $document->getLocale()]);
     }
 }
コード例 #9
0
 /**
  * Update the locale to the shadow locale, if it is enabled.
  *
  * Note that this should happen before the fallback locale has been resolved
  *
  * @param AbstractMappingEvent $event
  */
 public function handleHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ShadowLocaleBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $shadowLocaleEnabled = $this->getShadowLocaleEnabled($node, $locale);
     $document->setShadowLocaleEnabled($shadowLocaleEnabled);
     if (!$shadowLocaleEnabled) {
         return;
     }
     $shadowLocale = $this->getShadowLocale($node, $locale);
     $document->setShadowLocale($shadowLocale);
     $this->registry->updateLocale($document, $shadowLocale, $locale);
     $event->setLocale($shadowLocale);
 }
コード例 #10
0
 /**
  * It can deserialize persisted documents with routes.
  */
 public function testDeserializationPersisted()
 {
     $page = $this->createPage(['title' => 'Hello']);
     $this->manager->persist($page, 'de');
     $this->manager->flush();
     $result = $this->serializer->serialize($page, 'json');
     $page = $this->serializer->deserialize($result, PageDocument::class, 'json');
     $this->assertInstanceOf(PageDocument::class, $page);
     $this->assertEquals('Hello', $page->getStructure()->getProperty('title')->getValue());
     $this->assertEquals('de', $this->registry->getOriginalLocaleForDocument($page));
 }
コード例 #11
0
 public function testRun()
 {
     $this->initPhpcr();
     $snippet = $this->documentManager->create('snippet');
     $snippet->setStructureType('car');
     $snippet->setTitle('Hallo');
     $snippet->getStructure()->bind(['description' => 'This is a perfect description.']);
     $this->documentManager->persist($snippet, 'en', ['parent_path' => '/cmf/snippets/car']);
     $this->documentManager->flush();
     $this->tester->execute(['srcLocale' => 'en', 'destLocale' => 'de']);
     $output = $this->tester->getDisplay();
     $this->assertContains('Done', $output);
     $this->documentRegistry->clear();
     $resultEN = $this->documentManager->find($snippet->getUuid(), 'en');
     $resultDE = $this->documentManager->find($snippet->getUuid(), 'de');
     $this->assertEquals('Hallo', $resultDE->getTitle());
     $this->assertEquals('Hallo', $resultEN->getTitle());
     $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('description')->getValue());
     $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('description')->getValue());
 }
コード例 #12
0
 private function handleRegister(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     $node = $event->getNode();
     $locale = $event->getLocale();
     if ($this->documentRegistry->hasDocument($document)) {
         $this->documentRegistry->updateLocale($document, $locale);
         return;
     }
     $this->documentRegistry->registerDocument($document, $node, $locale);
 }
コード例 #13
0
 /**
  * @param ObjectEvent $event
  */
 public function onPostDeserialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     if (!$document instanceof PageDocument) {
         return;
     }
     if (!$document->getUuid()) {
         return;
     }
     try {
         $node = $this->session->getNodeByIdentifier($document->getUuid());
     } catch (ItemNotFoundException $e) {
         return;
     }
     if ($this->registry->hasNode($node)) {
         $registeredDocument = $this->registry->getDocumentForNode($node);
         $this->registry->deregisterDocument($registeredDocument);
     }
     // TODO use the original locale somehow
     $this->registry->registerDocument($document, $node, $document->getLocale());
 }
コード例 #14
0
 /**
  * Resolve the destination name on move and copy events.
  *
  * @param MoveEvent $event
  */
 private function handleMoveCopy(MoveEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof AutoNameBehavior) {
         return;
     }
     $destId = $event->getDestId();
     $node = $this->registry->getNodeForDocument($document);
     $destNode = $this->nodeManager->find($destId);
     $nodeName = $this->resolver->resolveName($destNode, $node->getName());
     $event->setDestName($nodeName);
 }
コード例 #15
0
 public function testRun()
 {
     $this->initPhpcr();
     $page = $this->documentManager->create('page');
     $page->setStructureType('default');
     $page->setTitle('Hallo');
     $page->getStructure()->bind(['article' => 'This is a perfect description.']);
     $page->setResourceSegment('/hallo');
     $this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']);
     $this->documentManager->flush();
     $this->tester->execute(['webspaceKey' => 'sulu_io', 'srcLocale' => 'de', 'destLocale' => 'en']);
     $output = $this->tester->getDisplay();
     $this->assertContains('Done', $output);
     $this->documentRegistry->clear();
     $resultEN = $this->documentManager->find($page->getUuid(), 'en');
     $resultDE = $this->documentManager->find($page->getUuid(), 'de');
     $this->assertEquals('Hallo', $resultDE->getTitle());
     $this->assertEquals('Hallo', $resultEN->getTitle());
     $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('article')->getValue());
     $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('article')->getValue());
     $this->assertEquals('/hallo', $resultDE->getResourceSegment());
     $this->assertEquals('/hallo', $resultEN->getResourceSegment());
 }
コード例 #16
0
 /**
  * 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());
 }
コード例 #17
0
 /**
  * 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;
 }
コード例 #18
0
ファイル: Webspace.php プロジェクト: sulu/sulu
 /**
  * Loops all documents and imports all properties of the documents.
  *
  * @param BasePageDocument $document
  * @param string $structureType
  * @param string $webspaceKey
  * @param string $locale
  * @param string $format
  * @param array $data
  */
 protected function setDocumentData(BasePageDocument $document, $structureType, $webspaceKey, $locale, $format, $data)
 {
     $structure = $this->structureManager->getStructure($structureType);
     $properties = $structure->getProperties(true);
     $node = $this->documentRegistry->getNodeForDocument($document);
     $node->setProperty(sprintf('i18n:%s-template', $locale), $structureType);
     $state = $this->getParser($format)->getPropertyData('state', $data, null, null, 2);
     $node->setProperty(sprintf('i18n:%s-state', $locale), $state);
     if ($this->getParser($format)->getPropertyData('title', $data) === '') {
         $this->addException(sprintf('Document(%s) has not set any title', $document->getUuid()), 'ignore');
         return false;
     }
     // import all content data
     foreach ($properties as $property) {
         $value = $this->getParser($format)->getPropertyData($property->getName(), $data, $property->getContentTypeName());
         // don't generate a new url when one exists
         $doImport = true;
         if ($property->getContentTypeName() == 'resource_locator') {
             $doImport = false;
             if (!$document->getResourceSegment()) {
                 $doImport = true;
                 $parent = $document->getParent();
                 if ($parent instanceof BasePageDocument) {
                     $parentUuid = $parent->getUuid();
                     $value = $this->generateUrl($structure->getPropertiesByTagName('sulu.rlp.part'), $parentUuid, $webspaceKey, $locale, $format, $data);
                 }
             }
         }
         // import property data
         if ($doImport) {
             $this->importProperty($property, $node, $structure, $value, $webspaceKey, $locale, $format);
         }
     }
     // import extensions
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $key => $extension) {
         $this->importExtension($extension, $key, $node, $data, $webspaceKey, $locale, $format);
     }
     // set required data
     $document->setTitle($this->getParser($format)->getPropertyData('title', $data));
     return true;
 }
コード例 #19
0
ファイル: DocumentSubscriber.php プロジェクト: sulu/sulu
 /**
  * @param ObjectEvent $event
  */
 public function onPostDeserialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     // only register documents
     if (!$this->metadataFactory->hasMetadataForClass(get_class($document))) {
         return;
     }
     if (!$document->getUuid()) {
         return;
     }
     try {
         $node = $this->nodeManager->find($document->getUuid());
     } catch (DocumentNotFoundException $e) {
         return;
     }
     if ($this->registry->hasNode($node, $document->getLocale())) {
         $registeredDocument = $this->registry->getDocumentForNode($node, $document->getLocale());
         $this->registry->deregisterDocument($registeredDocument);
     }
     // TODO use the original locale somehow
     if (!$this->registry->hasDocument($document)) {
         $this->registry->registerDocument($document, $node, $document->getLocale());
     }
 }
コード例 #20
0
 /**
  * It should deregister the document on the REMOVE event.
  */
 public function testHandleRemove()
 {
     $this->removeEvent->getDocument()->willReturn($this->document);
     $this->registry->deregisterDocument($this->document)->shouldBeCalled();
     $this->subscriber->handleRemove($this->removeEvent->reveal());
 }
コード例 #21
0
 /**
  * Create a new collection of referrers from a list of referencing items.
  *
  * @param $document
  *
  * @return ReferrerCollection
  */
 public function createReferrerCollection($document)
 {
     $node = $this->registry->getNodeForDocument($document);
     $locale = $this->registry->getOriginalLocaleForDocument($document);
     return new ReferrerCollection($node, $this->dispatcher, $locale);
 }
コード例 #22
0
 /**
  * Return the UUID of the given document.
  *
  * @param object $document
  *
  * @return string
  */
 public function getUuid($document)
 {
     return $this->documentRegistry->getNodeForDocument($document)->getIdentifier();
 }
コード例 #23
0
 /**
  * Remove the given documents node from PHPCR session and optionally
  * remove any references to the node.
  *
  * @param RemoveEvent $event
  */
 public function handleRemove(RemoveEvent $event)
 {
     $document = $event->getDocument();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $node->remove();
 }