Returns extensions for structure.
public getExtensions ( string $key ) : Sulu\Component\Content\Extension\ExtensionInterface[] | ||
$key | string | |
리턴 | Sulu\Component\Content\Extension\ExtensionInterface[] |
/** * {@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); }
/** * {@inheritdoc} */ public function toArray() { $result = []; foreach ($this->extensionManager->getExtensions($this->structureType) as $extension) { $result[$extension->getName()] = $this->offsetGet($extension->getName()); } return $result; }
/** * 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()); }
/** * 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; }
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; }