The "model" set of properties does not include UI elements
such as sections.
public getProperties ( ) : |
||
return |
public function bind($data, $clearMissing = true) { foreach ($this->structureMetadata->getProperties() as $childName => $child) { if (false === $clearMissing && !isset($data[$childName])) { continue; } $value = isset($data[$childName]) ? $data[$childName] : null; $property = $this->getProperty($childName); $property->setValue($value); } }
/** * {@inheritdoc} */ public function getProperties($flatten = false) { if ($flatten) { $items = $this->structure->getProperties(); } else { $items = $this->structure->getChildren(); } $propertyBridges = []; foreach ($items as $property) { $propertyBridges[$property->getName()] = $this->createLegacyPropertyFromItem($property); } return $propertyBridges; }
/** * 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()); }
/** * Returns all properties which are a URL field. * * @param StructureMetadata $structureMetadata The metadata in which the URL fields are searched * @param array $properties The properties which are URL fields are added to this array */ private function findUrlProperties(StructureMetadata $structureMetadata, array &$properties) { $structureName = $structureMetadata->getName(); foreach ($structureMetadata->getProperties() as $property) { if ($property->getType() === 'url') { $properties[$structureName][] = ['property' => $property]; } elseif ($property instanceof BlockMetadata) { $this->findUrlBlockProperties($property, $structureName, $properties); } } }
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; }
/** * Adds the properties of the structure to the serialization. * * @param StructureBehavior $document * @param VisitorInterface $visitor */ private function addStructureProperties(StructureMetadata $structureMetadata, StructureBehavior $document, VisitorInterface $visitor) { /** @var ManagedStructure $structure */ $structure = $document->getStructure(); $data = $structure->toArray(); foreach ($structureMetadata->getProperties() as $name => $property) { if ($name === 'title' || !array_key_exists($name, $data) || $property->hasTag('sulu.rlp')) { continue; } $visitor->addData($name, $data[$name]); } }