createProperty() public method

Create a new property.
public createProperty ( ItemMetadata $property, Sulu\Component\Content\Compat\StructureInterface $structure = null ) : Sulu\Component\Content\Compat\PropertyInterface
$property Sulu\Component\Content\Metadata\ItemMetadata
$structure Sulu\Component\Content\Compat\StructureInterface
return Sulu\Component\Content\Compat\PropertyInterface $property
Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function getProperty($name)
 {
     $this->init();
     if (isset($this->properties[$name])) {
         return $this->properties[$name];
     }
     if (!$this->node) {
         $this->node = $this->inspector->getNode($this->document);
     }
     $structureProperty = $this->structureMetadata->getProperty($name);
     $contentTypeName = $structureProperty->getType();
     $bridge = new StructureBridge($this->structureMetadata, $this->inspector, $this->legacyPropertyFactory, $this->document);
     if ($structureProperty->isLocalized()) {
         $locale = $this->inspector->getLocale($this->document);
         $property = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale, $bridge);
     } else {
         $property = $this->legacyPropertyFactory->createProperty($structureProperty);
     }
     $this->legacyProperties[$name] = $property;
     $property->setStructure($bridge);
     $contentType = $this->contentTypeManager->get($contentTypeName);
     $contentType->read($this->node, $property, null, null, null);
     $valueProperty = new PropertyValue($name, $property->getValue());
     $this->properties[$name] = $valueProperty;
     return $valueProperty;
 }
Beispiel #2
0
 private function createLegacyPropertyFromItem($item)
 {
     $name = $item->getName();
     if (isset($this->loadedProperties[$name])) {
         return $this->loadedProperties[$name];
     }
     $propertyBridge = $this->propertyFactory->createProperty($item, $this);
     if ($this->document) {
         $property = $this->getDocument()->getStructure()->getProperty($name);
         $propertyBridge->setPropertyValue($property);
     }
     $this->loadedProperties[$name] = $propertyBridge;
     return $propertyBridge;
 }
 private function doGetProperty($name, $contentTypeName, $locale)
 {
     $this->propertyMetadata->getType()->willReturn($contentTypeName);
     $this->structureMetadata->getProperty($name)->willReturn($this->propertyMetadata);
     $this->contentTypeManager->get($contentTypeName)->willReturn($this->contentType->reveal());
     if ($locale) {
         $this->propertyFactory->createTranslatedProperty($this->propertyMetadata->reveal(), $locale, Argument::type(StructureBridge::class))->willReturn($this->legacyProperty->reveal());
     } else {
         $this->propertyFactory->createProperty($this->propertyMetadata->reveal(), $locale)->willReturn($this->legacyProperty->reveal());
     }
     $this->contentType->read($this->node->reveal(), $this->legacyProperty->reveal(), null, null, null)->shouldBeCalledTimes(1);
     $property = $this->structure->getProperty($name);
     $this->assertInstanceOf(PropertyValue::class, $property);
     $this->assertEquals($name, $property->getName());
 }
 /**
  * It should create a block property.
  *
  * @depends testCreateProperty
  */
 public function testCreateBlock($property)
 {
     $this->setUpProperty($this->block);
     $this->component->getName()->willReturn('hai');
     $this->component->getChildren()->willReturn([$property->reveal()]);
     $this->component->title = ['de' => 'Testtitel', 'en' => 'Test title'];
     $this->block->getComponents()->willReturn([$this->component->reveal()]);
     $this->block->getDefaultComponentName()->willReturn('foobar');
     /** @var BlockProperty $blockProperty */
     $blockProperty = $this->factory->createProperty($this->block->reveal());
     $this->assertInstanceOf(BlockPropertyInterface::class, $blockProperty);
     $this->assertCount(1, $blockProperty->getTypes());
     $blockType = $blockProperty->getType('hai');
     $this->assertNotNull($blockType);
     $this->assertCount(1, $blockType->getChildProperties());
     $this->assertEquals('Testtitel', $blockType->getMetadata()->get('title', 'de'));
     $this->assertEquals('Test title', $blockType->getMetadata()->get('title', 'en'));
 }