diff --git a/composer.json b/composer.json index 13050e3..8c29143 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require": { "php": ">=7.2", - "a2lix/auto-form-bundle": "^0.2|^0.3|^0.4", + "a2lix/auto-form-bundle": ">=0.4.5", "symfony/config": "^3.4.30|^4.3|^5.0|^6.0", "symfony/dependency-injection": "^3.4.30|^4.3|^5.0|^6.0", "symfony/doctrine-bridge": "^3.4.30|^4.3|^5.0|^6.0", diff --git a/src/Form/EventListener/TranslationsListener.php b/src/Form/EventListener/TranslationsListener.php index 5098646..d402f85 100644 --- a/src/Form/EventListener/TranslationsListener.php +++ b/src/Form/EventListener/TranslationsListener.php @@ -42,13 +42,14 @@ public function preSetData(FormEvent $event): void { $form = $event->getForm(); - if (null === $formParent = $form->getParent()) { + $formOptions = $form->getConfig()->getOptions(); + $fieldsOptions = $this->getFieldsOptions($form, $formOptions); + + if ((!array_key_exists('mapped', $formOptions) || false !== $formOptions['mapped']) && null === $formParent = $form->getParent()) { throw new \RuntimeException('Parent form missing'); } - $formOptions = $form->getConfig()->getOptions(); - $fieldsOptions = $this->getFieldsOptions($form, $formOptions); - $translationClass = $this->getTranslationClass($formParent); + $translationClass = (!array_key_exists('mapped', $formOptions) || false !== $formOptions['mapped']) ? $this->getTranslationClass($formParent) : null; foreach ($formOptions['locales'] as $locale) { if (!isset($fieldsOptions[$locale])) { @@ -73,6 +74,10 @@ public function submit(FormEvent $event): void $data = $event->getData(); + if (array_key_exists('mapped', $formOptions) && false === $formOptions['mapped']) { + return; + } + foreach ($data as $locale => $translation) { // Remove useless Translation object if ((method_exists($translation, 'isEmpty') && $translation->isEmpty() && !\in_array($locale, $formOptions['required_locales'], true)) // Knp