예제 #1
0
 protected function setUp()
 {
     $this->initPhpcr();
     $this->extensions = [new TestExtension('test1', 'test1')];
     $this->mapper = $this->getContainer()->get('sulu.content.mapper');
     $this->nodeRepository = $this->getContainer()->get('sulu_content.node_repository');
     $this->extensionManager = $this->getContainer()->get('sulu_content.extension.manager');
     $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session');
     $this->extensionManager->addExtension(new TestExtension('test1', 'test1'));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function handlePersist(PersistEvent $event)
 {
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $document = $event->getDocument();
     if (!$document instanceof ExtensionBehavior) {
         return;
     }
     $structureType = $document->getStructureType();
     $node = $event->getNode();
     $extensionsData = $document->getExtensionsData();
     $webspaceName = $this->inspector->getWebspace($document);
     $prefix = $this->namespaceRegistry->getPrefix('extension_localized');
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $extension) {
         $extensionData = null;
         if (!isset($extensionsData[$extension->getName()])) {
             continue;
         }
         $extensionData = $extensionsData[$extension->getName()];
         $extension->setLanguageCode($locale, $prefix, $this->internalPrefix);
         $extension->save($node, $extensionData, $webspaceName, $locale);
     }
     $this->hydrate($event);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     $result = [];
     foreach ($this->extensionManager->getExtensions($this->structureType) as $extension) {
         $result[$extension->getName()] = $this->offsetGet($extension->getName());
     }
     return $result;
 }
예제 #4
0
 /**
  * Returns a select statement for excerpt data.
  */
 private function buildSelectorForExcerpt($locale, &$additionalFields)
 {
     $excerptStructure = $this->structureManager->getStructure('excerpt');
     $extension = $this->extensionManager->getExtension('', 'excerpt');
     foreach ($excerptStructure->getProperties(true) as $property) {
         $additionalFields[$locale][] = ['extension' => $extension, 'target' => 'excerpt', 'property' => $property->getName(), 'name' => $property->getName()];
     }
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function resolve(StructureInterface $structure)
 {
     $data = ['view' => [], 'content' => [], 'uuid' => $structure->getUuid(), 'creator' => $structure->getCreator(), 'changer' => $structure->getChanger(), 'created' => $structure->getCreated(), 'changed' => $structure->getChanged(), 'template' => $structure->getKey(), 'path' => $structure->getPath()];
     if ($structure instanceof PageBridge) {
         $data['extension'] = $structure->getExt()->toArray();
         $data['urls'] = $structure->getUrls();
         $data['published'] = $structure->getPublished();
         $data['shadowBaseLocale'] = $structure->getShadowBaseLanguage();
         foreach ($data['extension'] as $name => $value) {
             $extension = $this->extensionManager->getExtension($structure->getKey(), $name);
             $data['extension'][$name] = $extension->getContentData($value);
         }
     }
     foreach ($structure->getProperties(true) as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $data['view'][$property->getName()] = $contentType->getViewData($property);
         $data['content'][$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
예제 #6
0
파일: Webspace.php 프로젝트: sulu/sulu
 /**
  * Returns a flat array with the extensions of the given document.
  *
  * @param BasePageDocument $document
  * @param string $format
  *
  * @return array
  */
 protected function getExtensionData(BasePageDocument $document, $format)
 {
     $extensionData = [];
     foreach ($document->getExtensionsData()->toArray() as $extensionName => $extensionProperties) {
         /** @var \Sulu\Bundle\ContentBundle\Content\Structure\ExcerptStructureExtension $extension */
         $extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
         if ($extension instanceof ExportExtensionInterface) {
             $extensionData[$extensionName] = $extension->export($extensionProperties, $format);
         }
     }
     return $extensionData;
 }
예제 #7
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());
 }
예제 #8
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;
 }
예제 #9
0
파일: ContentMapper.php 프로젝트: sulu/sulu
 /**
  * TODO: Refactor this .. this should be handled in a listener or in the form, or something
  * {@inheritdoc}
  */
 public function saveExtension($uuid, $data, $extensionName, $webspaceKey, $locale, $userId)
 {
     $document = $this->loadDocument($uuid, $locale, ['exclude_ghost' => true]);
     if ($document === null) {
         throw new TranslatedNodeNotFoundException($uuid, $locale);
     }
     if (!$document instanceof ExtensionBehavior) {
         throw new \RuntimeException(sprintf('Document of class "%s" must implement the ExtensionableBehavior if it is to be extended', get_class($document)));
     }
     // save data of extensions
     $extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
     $node = $this->inspector->getNode($document);
     $extension->save($node, $data, $webspaceKey, $locale);
     $extensionData = $extension->load($node, $webspaceKey, $locale);
     $document->setExtension($extension->getName(), $extensionData);
     $this->documentManager->flush();
     $structure = $this->documentToStructure($document);
     $event = new ContentNodeEvent($node, $structure);
     $this->eventDispatcher->dispatch(ContentEvents::NODE_POST_SAVE, $event);
     return $structure;
 }
예제 #10
0
 public function getMetadata(Metadata $documentMetadata, StructureMetadata $structure)
 {
     $classMetadata = $this->factory->createClassMetadata($documentMetadata->getClass());
     $class = $documentMetadata->getReflectionClass();
     $indexMeta = $this->factory->createIndexMetadata();
     $indexMeta->setIdField($this->factory->createMetadataField('uuid'));
     $indexMeta->setLocaleField($this->factory->createMetadataField('locale'));
     $indexName = 'page';
     // See if the mapping overrides the default index and category name
     foreach ($this->mapping as $className => $mapping) {
         if ($documentMetadata->getAlias() !== $className && $class->name !== $className && false === $class->isSubclassOf($className)) {
             continue;
         }
         $indexName = $mapping['index'];
     }
     if ($indexName === 'page') {
         $indexMeta->setIndexName(new Expression('"page_"~object.getWebspaceName()'));
     } else {
         $indexMeta->setIndexName(new Value($indexName));
     }
     foreach ($structure->getProperties() as $property) {
         if ($property instanceof BlockMetadata) {
             $propertyMapping = new ComplexMetadata();
             foreach ($property->getComponents() as $component) {
                 foreach ($component->getChildren() as $componentProperty) {
                     if (false === $componentProperty->hasTag('sulu.search.field')) {
                         continue;
                     }
                     $tag = $componentProperty->getTag('sulu.search.field');
                     $tagAttributes = $tag['attributes'];
                     if (!isset($tagAttributes['index']) || $tagAttributes['index'] !== 'false') {
                         $propertyMapping->addFieldMapping($property->getName() . '.' . $componentProperty->getName(), ['type' => isset($tagAttributes['type']) ? $tagAttributes['type'] : 'string', 'field' => $this->factory->createMetadataProperty('[' . $componentProperty->getName() . ']'), 'aggregate' => true, 'indexed' => false]);
                     }
                 }
             }
             $indexMeta->addFieldMapping($property->getName(), ['type' => 'complex', 'mapping' => $propertyMapping, 'field' => $this->getContentField($property)]);
         } else {
             $this->mapProperty($property, $indexMeta);
         }
     }
     if ($class->isSubclassOf(ExtensionBehavior::class)) {
         $extensions = $this->extensionManager->getExtensions($structure->getName());
         foreach ($extensions as $extension) {
             foreach ($extension->getFieldMapping() as $name => $mapping) {
                 $indexMeta->addFieldMapping($name, $mapping);
             }
         }
     }
     if ($class->isSubclassOf(ResourceSegmentBehavior::class)) {
         $indexMeta->setUrlField($this->factory->createMetadataField('resourceSegment'));
     }
     if (!$indexMeta->getTitleField()) {
         if ($class->isSubclassOf(TitleBehavior::class)) {
             $indexMeta->setTitleField($this->factory->createMetadataProperty('title'));
             $indexMeta->addFieldMapping('title', ['type' => 'string', 'field' => $this->factory->createMetadataField('title'), 'aggregate' => true, 'indexed' => false]);
         }
     }
     if ($class->isSubclassOf(WebspaceBehavior::class)) {
         // index the webspace
         $indexMeta->addFieldMapping('webspace_key', ['type' => 'string', 'field' => $this->factory->createMetadataProperty('webspaceName')]);
     }
     if ($class->isSubclassOf(WorkflowStageBehavior::class)) {
         $indexMeta->addFieldMapping('state', ['type' => 'string', 'field' => $this->factory->createMetadataExpression('object.getWorkflowStage() == 1 ? "test" : "published"')]);
     }
     $indexMeta->addFieldMapping(self::FIELD_STRUCTURE_TYPE, ['type' => 'string', 'stored' => true, 'indexed' => false, 'field' => $this->factory->createMetadataProperty('structureType')]);
     $classMetadata->addIndexMetadata('_default', $indexMeta);
     return $classMetadata;
 }