eZ\Publish\Core\Helper\FieldsGroups\FieldsGroupsList::getGroups PHP Method

getGroups() public method

The list is a hash, with the group identifier as the key, and the human readable string as the value. If groups are meant to be translated, they should be translated inside this service.
public getGroups ( ) : array
return array hash, with the group identifier as the key, and the human readable string as the value.
    public function getGroups();

Usage Example

 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);
     });
 }