From 3e62c15c4ffff9fe72c06e6915c7be93ccca77c2 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" <nek.dev@gmail.com> Date: Thu, 16 Apr 2020 21:47:17 +0200 Subject: [PATCH] Update heahdude example Now working, type error catching was missing. --- src/Controller/TestHeahdudeController.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Controller/TestHeahdudeController.php b/src/Controller/TestHeahdudeController.php index 7d375fc..d7c1b69 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', -- GitLab