diff --git a/src/Form/Manipulator/DoctrineORMManipulator.php b/src/Form/Manipulator/DoctrineORMManipulator.php index 2554fd8..8cbfe23 100644 --- a/src/Form/Manipulator/DoctrineORMManipulator.php +++ b/src/Form/Manipulator/DoctrineORMManipulator.php @@ -31,21 +31,27 @@ public function __construct(DoctrineORMInfo $doctrineORMInfo, array $globalExclu public function getFieldsConfig(FormInterface $form): array { - $class = $this->getDataClass($form); $formOptions = $form->getConfig()->getOptions(); - - // Filtering to remove excludedFields - $objectFieldsConfig = $this->doctrineORMInfo->getFieldsConfig($class); - $validObjectFieldsConfig = $this->filteringValidObjectFields($objectFieldsConfig, $formOptions['excluded_fields']); - - if (empty($formOptions['fields'])) { - return $validObjectFieldsConfig; + if (array_key_exists('mapped', $formOptions) && false !== $formOptions) { + $class = null; + $validObjectFieldsConfig = []; + } else { + $class = $this->getDataClass($form); + + // Filtering to remove excludedFields + $objectFieldsConfig = $this->doctrineORMInfo->getFieldsConfig($class); + $validObjectFieldsConfig = $this->filteringValidObjectFields($objectFieldsConfig, $formOptions['excluded_fields']); + + if (empty($formOptions['fields'])) { + return $validObjectFieldsConfig; + } } $fields = []; - foreach ($formOptions['fields'] as $formFieldName => $formFieldConfig) { - $this->checkFieldIsValid($formFieldName, $formFieldConfig, $validObjectFieldsConfig, $class); + if ($class) { + $this->checkFieldIsValid($formFieldName, $formFieldConfig, $validObjectFieldsConfig, $class); + } if (null === $formFieldConfig) { continue; diff --git a/src/Form/Type/AutoFormType.php b/src/Form/Type/AutoFormType.php index e48a0f6..67da5e0 100644 --- a/src/Form/Type/AutoFormType.php +++ b/src/Form/Type/AutoFormType.php @@ -40,13 +40,5 @@ public function configureOptions(OptionsResolver $resolver): void 'fields' => [], 'excluded_fields' => [], ]); - - $resolver->setNormalizer('data_class', function (Options $options, $value): string { - if (empty($value)) { - throw new \RuntimeException('Missing "data_class" option of "AutoFormType".'); - } - - return $value; - }); } }