TODO: Components are basically Snippets, but Snippets are loaded as Structures
Inheritance: extends PropertyMetadata
 /**
  * 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'));
 }
Example #2
0
 /**
  * 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;
     }
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * Upgrades the given block property to the new date representation.
  *
  * @param BlockMetadata $blockProperty
  * @param array $components
  * @param NodeInterface $node
  * @param string $locale
  * @param bool $up
  */
 private function upgradeBlockProperty(BlockMetadata $blockProperty, array $components, NodeInterface $node, $locale, $up)
 {
     $componentNames = array_map(function ($item) {
         return $item['component']->getName();
     }, $components);
     $lengthName = sprintf('i18n:%s-%s-length', $locale, $blockProperty->getName());
     $length = $node->getPropertyValue($lengthName);
     for ($i = 0; $i < $length; ++$i) {
         $type = $node->getPropertyValue(sprintf('i18n:%s-%s-type#%s', $locale, $blockProperty->getName(), $i));
         if (!in_array($type, $componentNames)) {
             continue;
         }
         foreach ($components[$type]['children'] as $child) {
             $name = sprintf('i18n:%s-%s-%s#%s', $locale, $blockProperty->getName(), $child->getName(), $i);
             if (!$node->hasProperty($name)) {
                 continue;
             }
             $value = $node->getPropertyValue($name);
             if ($up) {
                 $value = $this->upgradeDate($value);
             } else {
                 $value = $this->downgradeDate($value);
             }
             $node->setProperty($name, $value);
         }
     }
 }
Example #5
0
 /**
  * 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();
             }
         }
     }
 }
Example #6
0
 /**
  * Creates and Returns a property-array for content-type Block.
  *
  * @param BlockMetadata $property
  * @param PropertyValue $propertyValue
  * @param $format
  *
  * @return array
  */
 protected function getBlockPropertyData(BlockMetadata $property, $propertyValue, $format)
 {
     $children = [];
     $blockDataList = $this->contentExportManager->export($property->getType(), $propertyValue);
     foreach ($blockDataList as $blockData) {
         $blockType = $blockData['type'];
         $block = $this->getPropertiesContentData($property->getComponentByName($blockType)->getChildren(), $blockData, $format);
         $block['type'] = $this->createProperty('type', $blockType, $this->contentExportManager->getOptions($property->getType(), $format), $property->getType() . '_type');
         $children[] = $block;
     }
     return $this->createProperty($property->getName(), null, $this->contentExportManager->getOptions($property->getType(), $format), $property->getType(), $children);
 }