form-extensions icon indicating copy to clipboard operation
form-extensions copied to clipboard

Add nested fields form type, which stores multiple nested fields, groups of fields and collections of fields in one json field

Open mesiarm opened this issue 3 years ago • 2 comments

Feature Request

Example of usage :

protected function configureFormFields(FormMapper $formMapper): void
    {
        $formMapper->add('contactInfo', NestedFieldsType::class, [
            'subfields' => [
                [
                    'items', CollectionType::class, [
                    'subfields' => [
                        ['title', TextType::class],
                        ['image', ModelListType::class, ['link_parameters' => ['context' => 'post_thumbnail']]],
                    ]
                ]
                ],
                ['group', GroupType::class, [
                    'subfields' => [
                        ['title', TextType::class],
                        ['image', ModelListType::class, ['link_parameters' => ['context' => 'post_thumbnail']],
                        ]
                    ]
                ],
                ],
                ['title', TextType::class],
                ['content', CKEditorType::class],
            ]]);
    }

Example of resulting json:

{
  "items": [
    {
      "title": "Test",
      "image": "image.png"
    },
    {
      "title": "Test 2",
      "image": "image.png"
    },
    {
      "title": "Test 3",
      "image": "image.png"
    }
  ],
  "group": {
    "title": "Test",
    "image": "image.png"
  },
  "title": "Test",
  "content": "<p>Test <strong>Bold</strong></p>"
}

mesiarm avatar Oct 07 '22 07:10 mesiarm

FormMapper field type are just working like a basic Symfony FormType. So you can implement you own FormType.

then it will be easy to provide a PR to https://github.com/sonata-project/form-extensions

VincentLanglet avatar Oct 07 '22 08:10 VincentLanglet

Maybe It´s simmilar to the ImmutableArrayType

mesiarm avatar Oct 07 '22 13:10 mesiarm

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 05 '23 14:04 github-actions[bot]