/** * 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')); }
/** * Adds the block property to the list, if it contains a URL field. * * @param BlockMetadata $property The block property to check * @param string $structureName The name of the structure the property belongs to * @param array $properties The list of properties, to which the block is added if it is a URL field */ private function findUrlBlockProperties(BlockMetadata $property, $structureName, array &$properties) { $result = ['property' => $property, 'components' => []]; foreach ($property->getComponents() as $component) { $componentResult = ['component' => $component, 'children' => []]; foreach ($component->getChildren() as $childProperty) { if ($childProperty->getType() === 'url') { $componentResult['children'][$childProperty->getName()] = $childProperty; } } if (count($componentResult['children']) > 0) { $result['components'][$component->getName()] = $componentResult; } } if (count($result['components']) > 0) { $properties[$structureName][] = $result; } }
private function createBlockProperty(BlockMetadata $property, StructureInterface $structure = null) { $blockProperty = new BlockProperty($property->getName(), ['title' => $property->title, 'info_text' => $property->description], $property->getDefaultComponentName(), $property->isRequired(), $property->isLocalized(), $property->getMaxOccurs(), $property->getMinOccurs(), $property->getParameters(), [], $property->getColspan()); $blockProperty->setStructure($structure); foreach ($property->getComponents() as $component) { $blockPropertyType = new BlockPropertyType($component->getName(), ['title' => $component->title, 'info_text' => $component->description]); foreach ($component->getChildren() as $property) { $blockPropertyType->addChild($this->createProperty($property, $structure)); } $blockProperty->addType($blockPropertyType); } return $blockProperty; }
/** * Adds the block property to the list, if it contains a date field. * * @param BlockMetadata $property The block property to check * @param string $structureName The name of the structure the property belongs to * @param array $properties The list of properties, to which the block is added if it is a date field */ private function findDateBlockProperties(BlockMetadata $property, $structureName, array &$properties) { foreach ($property->getComponents() as $component) { foreach ($component->getChildren() as $childProperty) { if ($childProperty->getType() === 'date') { $properties[$structureName][] = $property->getName(); } } } }