diff --git a/src/Controller/TestHeahdudeController.php b/src/Controller/TestHeahdudeController.php index 7d375fce30c3f24ac42b3792743e00caf738444f..d7c1b69f0addac805e305ddcb0260f8d5f24ef64 100644 --- a/src/Controller/TestHeahdudeController.php +++ b/src/Controller/TestHeahdudeController.php @@ -47,34 +47,24 @@ class TestHeahdudeController extends AbstractController $forms = iterator_to_array($forms); try { $viewData = new ParentModel($forms['content']->getData(), new ColorVo($forms['color']->getData())); - } catch (InvalidColorException $error) { - // What to do here ?! - // This does not work - // $forms['colorCondition']->setData(false); - // Even if it would, the error path is wrong! - } + + // Catching all potential exception will result in null data in the form, which is ok. + } catch (InvalidColorException $error) {} catch (\TypeError $error) {} } }) ->add('color', ColorType::class, [ + // Those constraints will act on form data, not view data. The form data remains not altered if there + // is an exception while processing the datamapper. 'constraints' => [ new Type(['type' => 'string']), new Callback(['callback' => ColorVo::class . '::validateColor']) ] ]) ->add('content', TextType::class) - ->add('colorCondition', CheckboxType::class, [ - 'label' => 'Accept color', - 'required' => false, - 'mapped' => false, - 'empty_data' => true, - 'constraints' => new IsTrue(['message' => 'Wrong color input']) - ]) ->getForm(); $form->submit(['color' => 10, 'content' => 'foobar']); - dump($form->getErrors(true, true)); - return $this->json([ 'message' => 'Welcome to your new controller!', 'path' => 'src/Controller/TestVoFormController.php',