Used to group fields definitions, and apply this grouping when editing / viewing content.
 public function processAddFieldDefinition(FormActionEvent $event)
 {
     // Reload the draft, to make sure we include any changes made in the current form submit
     $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($event->getData()->contentTypeDraft->id);
     $fieldTypeIdentifier = $event->getForm()->get('fieldTypeSelection')->getData();
     $maxFieldPos = 0;
     foreach ($contentTypeDraft->fieldDefinitions as $existingFieldDef) {
         if ($existingFieldDef->position > $maxFieldPos) {
             $maxFieldPos = $existingFieldDef->position;
         }
     }
     $fieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => sprintf('new_%s_%d', $fieldTypeIdentifier, count($contentTypeDraft->fieldDefinitions) + 1), 'names' => [$event->getOption('languageCode') => 'New FieldDefinition'], 'position' => $maxFieldPos + 1]);
     if (isset($this->groupsList)) {
         $fieldDefCreateStruct->fieldGroup = $this->groupsList->getDefaultGroup();
     }
     $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreateStruct);
 }
 public function testAddFieldDefinition()
 {
     $languageCode = 'fre-FR';
     $existingFieldDefinitions = [new FieldDefinition(), new FieldDefinition()];
     $contentTypeDraft = new ContentTypeDraft(['innerContentType' => new ContentType(['fieldDefinitions' => $existingFieldDefinitions])]);
     $fieldTypeIdentifier = 'ezstring';
     $expectedNewFieldDefIdentifier = sprintf('new_%s_%d', $fieldTypeIdentifier, count($existingFieldDefinitions) + 1);
     $fieldTypeSelectionForm = $this->getMock('\\Symfony\\Component\\Form\\FormInterface');
     $fieldTypeSelectionForm->expects($this->once())->method('getData')->willReturn($fieldTypeIdentifier);
     $mainForm = $this->getMock('\\Symfony\\Component\\Form\\FormInterface');
     $mainForm->expects($this->once())->method('get')->with('fieldTypeSelection')->willReturn($fieldTypeSelectionForm);
     $expectedFieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => $expectedNewFieldDefIdentifier, 'names' => [$languageCode => 'New FieldDefinition'], 'position' => 1, 'fieldGroup' => 'content']);
     $this->contentTypeService->expects($this->once())->method('loadContentTypeDraft')->with($contentTypeDraft->id)->willReturn($contentTypeDraft);
     $this->contentTypeService->expects($this->once())->method('addFieldDefinition')->with($contentTypeDraft, $this->equalTo($expectedFieldDefCreateStruct));
     $this->groupsList->expects($this->once())->method('getDefaultGroup')->will($this->returnValue('content'));
     $event = new FormActionEvent($mainForm, new ContentTypeData(['contentTypeDraft' => $contentTypeDraft]), 'addFieldDefinition', ['languageCode' => $languageCode]);
     $this->formProcessor->processAddFieldDefinition($event);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $fieldsGroups = [];
     if (isset($this->groupsList)) {
         $fieldsGroups = array_flip($this->groupsList->getGroups());
     }
     $translatablePropertyTransformer = new TranslatablePropertyTransformer($options['languageCode']);
     $builder->add($builder->create('name', TextType::class, ['property_path' => 'names', 'label' => 'field_definition.name'])->addModelTransformer($translatablePropertyTransformer))->add('identifier', TextType::class, ['label' => 'field_definition.identifier'])->add($builder->create('description', TextType::class, ['property_path' => 'descriptions', 'required' => false, 'label' => 'field_definition.description'])->addModelTransformer($translatablePropertyTransformer))->add('isRequired', CheckboxType::class, ['required' => false, 'label' => 'field_definition.is_required'])->add('isTranslatable', CheckboxType::class, ['required' => false, 'label' => 'field_definition.is_translatable'])->add('fieldGroup', ChoiceType::class, ['choices' => $fieldsGroups, 'choices_as_values' => true, 'required' => false, 'label' => 'field_definition.field_group'])->add('position', IntegerType::class, ['label' => 'field_definition.position'])->add('selected', CheckboxType::class, ['required' => false, 'mapped' => false]);
     // Hook on form generation for specific FieldType needs
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var \EzSystems\RepositoryForms\Data\FieldDefinitionData $data */
         $data = $event->getData();
         $form = $event->getForm();
         $fieldTypeIdentifier = $data->getFieldTypeIdentifier();
         $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
         // isSearchable field should be present only if the FieldType allows it.
         $form->add('isSearchable', CheckboxType::class, ['required' => false, 'disabled' => !$fieldType->isSearchable(), 'label' => 'field_definition.is_searchable']);
         // Let fieldType mappers do their jobs to complete the form.
         $this->fieldTypeMapperDispatcher->map($form, $data);
     });
 }