Exemplo n.º 1
0
 public function testLoadMetadata()
 {
     $this->metadata->getReflectionClass()->willReturn(new \ReflectionClass($this->document->reveal()));
     $this->metadata->addFieldMapping('redirectType', Argument::any())->shouldBeCalled();
     $this->metadata->addFieldMapping('redirectExternal', Argument::any())->shouldBeCalled();
     $this->metadata->addFieldMapping('redirectTarget', Argument::any())->shouldBeCalled();
     $this->subscriber->handleMetadataLoad($this->event->reveal());
 }
Exemplo n.º 2
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';
     $categoryName = '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'];
         $categoryName = $mapping['category'];
     }
     $indexMeta->setCategoryName($categoryName);
     $indexMeta->setIndexName($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(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;
 }