Form/Type/DynamicFormType.php
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        /** @var Form $formEntity */
        $formEntity = $options['formEntity'];
        $locale = $options['locale'];
        $type = $options['type'];
        $typeId = $options['typeId'];
        $name = $options['name'];

        if (!$translation = $formEntity->getTranslation($locale)) {
            throw new \Exception(
                sprintf('The form with the ID "%s" does not exist for the locale "%s"!', $formEntity->getId(), $locale)
            );
        }

        $currentWidthValue = 0;
        $fields = $formEntity->getFields();

        foreach ($fields as $key => $field) {
            $fieldTranslation = $field->getTranslation($locale);

            if (!$fieldTranslation) {
                continue;
            }

            $options = [
                'constraints' => [],
                'attr' => [],
                'translation_domain' => false,
            ];

            $title = $fieldTranslation->getTitle();
            $placeholder = $fieldTranslation->getPlaceholder();
            $width = $field->getWidth() ?: 'full';

            $nextField = null;
            $nextWidth = 'full';
            if (isset($fields[$key + 1])) {
                $nextWidth = $fields[$key + 1]->getWidth();
            }

            $lastWidth = $this->getLastWidth($currentWidthValue, $width, $nextWidth);

            $options['label'] = $title ?: false;
            $options['required'] = $field->getRequired();
            $options['attr']['width'] = $width;
            $options['attr']['widthNumber'] = $this->getItemWidthNumber($width);
            $options['attr']['lastWidth'] = $lastWidth;

            if ($placeholder) {
                $options['attr']['placeholder'] = $placeholder;
            }

            // required
            if ($field->getRequired()) {
                $options['constraints'][] = new NotBlank();
            }

            $this->typePool->get($field->getType())->build($builder, $field, $locale, $options);
        }

        // Add hidden locale. (de, en, ...)
        $builder->add('locale', HiddenType::class, [
            'data' => $locale,
            'mapped' => false,
        ]);

        // Add hidden type field. (page, article, event, blog, ...)
        $builder->add('type', HiddenType::class, [
            'data' => $type,
            'mapped' => false,
        ]);

        // Add hidden typeId field. (UUID, Database id, ...)
        $builder->add('typeId', HiddenType::class, [
            'data' => $typeId,
            'mapped' => false,
        ]);

        // Add hidden formId. (id, uuid,…)
        $builder->add('formId', HiddenType::class, [
            'data' => $formEntity->getId(),
            'mapped' => false,
        ]);

        // Add hidden formName field. (Name of "form_select"-content-type.)
        $builder->add('formName', HiddenType::class, [
            'data' => $name,
            'mapped' => false,
        ]);

        // Add hidden formName field. (Name of "form_select"-content-type.)
        $checksum = $this->checksum->get($type, $typeId, $formEntity->getId(), $name);
        $builder->add('checksum', HiddenType::class, [
            'data' => $checksum,
            'mapped' => false,
        ]);

        // Add submit button.
        $builder->add(
            'submit',
            SubmitType::class,
            [
                'label' => $translation->getSubmitLabel(),
                'translation_domain' => false,
                'attr' => [
                    'width' => 'full',
                    'widthNumber' => $this->getItemWidthNumber('full'),
                    'lastWidth' => true,
                ],
            ]
        );
    }
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        /** @var Form $formEntity */
        $formEntity = $options['formEntity'];
        $locale = $options['locale'];
        $type = $options['type'];
        $typeId = $options['typeId'];
        $name = $options['name'];

        if (!$translation = $formEntity->getTranslation($locale)) {
            throw new \Exception(
                sprintf('The form with the ID "%s" does not exist for the locale "%s"!', $formEntity->getId(), $locale)
            );
        }

        $currentWidthValue = 0;
        $fields = $formEntity->getFields();

        foreach ($fields as $key => $field) {
            $fieldTranslation = $field->getTranslation($locale);

            if (!$fieldTranslation) {
                continue;
            }

            $options = [
                'constraints' => [],
                'attr' => [],
                'translation_domain' => false,
            ];

            $title = $fieldTranslation->getTitle();
            $placeholder = $fieldTranslation->getPlaceholder();
            $width = $field->getWidth() ?: 'full';

            $nextField = null;
            $nextWidth = 'full';
            if (isset($fields[$key + 1])) {
                $nextWidth = $fields[$key + 1]->getWidth();
            }

            $lastWidth = $this->getLastWidth($currentWidthValue, $width, $nextWidth);

            $options['label'] = $title ?: false;
            $options['required'] = $field->getRequired();
            $options['attr']['width'] = $width;
            $options['attr']['widthNumber'] = $this->getItemWidthNumber($width);
            $options['attr']['lastWidth'] = $lastWidth;

            if ($placeholder) {
                $options['attr']['placeholder'] = $placeholder;
            }

            // required
            if ($field->getRequired()) {
                $options['constraints'][] = new NotBlank();
            }

            $this->typePool->get($field->getType())->build($builder, $field, $locale, $options);
        }

        // Add hidden locale. (de, en, ...)
        $builder->add('locale', HiddenType::class, [
            'data' => $locale,
            'mapped' => false,
        ]);

        // Add hidden type field. (page, article, event, blog, ...)
        $builder->add('type', HiddenType::class, [
            'data' => $type,
            'mapped' => false,
        ]);

        // Add hidden typeId field. (UUID, Database id, ...)
        $builder->add('typeId', HiddenType::class, [
            'data' => $typeId,
            'mapped' => false,
        ]);

        // Add hidden formId. (id, uuid,…)
        $builder->add('formId', HiddenType::class, [
            'data' => $formEntity->getId(),
            'mapped' => false,
        ]);

        // Add hidden formName field. (Name of "form_select"-content-type.)
        $builder->add('formName', HiddenType::class, [
            'data' => $name,
            'mapped' => false,
        ]);

        // Add hidden formName field. (Name of "form_select"-content-type.)
        $checksum = $this->checksum->get($type, $typeId, $formEntity->getId(), $name);
        $builder->add('checksum', HiddenType::class, [
            'data' => $checksum,
            'mapped' => false,
        ]);

        // Add submit button.
        $builder->add(
            'submit',
            SubmitType::class,
            [
                'label' => $translation->getSubmitLabel(),
                'translation_domain' => false,
                'attr' => [
                    'width' => 'full',
                    'widthNumber' => $this->getItemWidthNumber('full'),
                    'lastWidth' => true,
                ],
            ]
        );
    }
{@inheritdoc}