Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function initializeLayoutFactoryBuilder(LayoutFactoryBuilderInterface $layoutFactoryBuilder)
 {
     parent::initializeLayoutFactoryBuilder($layoutFactoryBuilder);
     $this->formLayoutBuilder = new GroupingFormLayoutBuilder();
     $this->formLayoutBuilder->addSimpleFormTypes(['choice', 'datetime', 'date', 'time']);
     $layoutFactoryBuilder->addType(new Type\RootType())->addType(new Type\BodyType())->addType(new Type\FormType($this->formLayoutBuilder))->addType(new Type\FormStartType())->addType(new Type\FormEndType())->addType(new Type\FormFieldType())->addType(new Type\FieldsetType())->addType(new Type\HeadType())->addType(new Type\MetaType())->addType(new Type\ScriptType())->addType(new Type\StyleType())->addType(new Type\ExternalResourceType())->addType(new Type\TextType())->addType(new Type\LinkType())->addType(new Type\ButtonType())->addType(new Type\ButtonGroupType())->addType(new Type\ListType())->addType(new Type\OrderedListType())->addType(new Type\ListItemType())->addType(new Type\InputType());
 }
 public function testGroupingByParentFieldPath()
 {
     $options = $this->getOptions();
     $options['groups'] = ['group1' => ['title' => 'Group 1', 'fields' => ['field2']], 'group2' => ['title' => 'Group 2', 'default' => true], 'group3' => ['title' => 'Group 3']];
     $form = $this->getForm();
     $formAccessor = new FormAccessor($form);
     $form->add($this->getForm(false, 'type1', 'field1'));
     $childForm = $this->getForm(true, 'type2', 'field2');
     $childForm->add($this->getForm(false, 'type21', 'field21'));
     $childForm->add($this->getForm(false, 'type22', 'field22'));
     $form->add($childForm);
     $this->layoutManipulator->expects($this->at(0))->method('add')->with(self::FIELD_PREFIX . 'field1', self::GROUP_PREFIX . 'group2', FormFieldType::NAME, ['form_name' => self::FORM_NAME, 'field_path' => 'field1'])->will($this->returnSelf());
     $this->layoutManipulator->expects($this->at(1))->method('add')->with(self::FIELD_PREFIX . 'field2:field21', self::GROUP_PREFIX . 'group1', FormFieldType::NAME, ['form_name' => self::FORM_NAME, 'field_path' => 'field2.field21'])->will($this->returnSelf());
     $this->layoutManipulator->expects($this->at(2))->method('add')->with(self::FIELD_PREFIX . 'field2:field22', self::GROUP_PREFIX . 'group1', FormFieldType::NAME, ['form_name' => self::FORM_NAME, 'field_path' => 'field2.field22'])->will($this->returnSelf());
     $this->layoutManipulator->expects($this->at(3))->method('add')->with(self::GROUP_PREFIX . 'group1', self::ROOT_ID, FieldsetType::NAME, ['title' => 'Group 1'])->will($this->returnSelf());
     $this->layoutManipulator->expects($this->at(4))->method('add')->with(self::GROUP_PREFIX . 'group2', self::ROOT_ID, FieldsetType::NAME, ['title' => 'Group 2'])->will($this->returnSelf());
     $this->layoutManipulator->expects($this->exactly(5))->method('add');
     $this->builder->build($formAccessor, $this->blockBuilder, $options);
     $this->assertSame(['field1' => self::FIELD_PREFIX . 'field1', 'field2.field21' => self::FIELD_PREFIX . 'field2:field21', 'field2.field22' => self::FIELD_PREFIX . 'field2:field22'], $formAccessor->getProcessedFields());
 }