From 04c0f5e9e7bf166b29ba1fb1070f550316985fb2 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 14 Sep 2018 15:08:51 +0200 Subject: [PATCH] Optimized forms for user source --- application/src/Entity/UserSource.php | 2 ++ application/src/Form/NameSourceType.php | 22 ++++++++++++++++++---- application/src/Form/UserSourceType.php | 20 ++++++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/application/src/Entity/UserSource.php b/application/src/Entity/UserSource.php index ff14834..5f4807d 100644 --- a/application/src/Entity/UserSource.php +++ b/application/src/Entity/UserSource.php @@ -24,6 +24,8 @@ class UserSource extends AbstractSource implements UserSourceInterface protected $user; /** + * @Assert\Type(type="App\Entity\NameSource") + * @Assert\Valid() * @ORM\OneToOne(targetEntity="NameSource",cascade={"persist", "remove"}) * @ORM\JoinColumn(name="name_id", referencedColumnName="id") * diff --git a/application/src/Form/NameSourceType.php b/application/src/Form/NameSourceType.php index 63020a7..58576c9 100644 --- a/application/src/Form/NameSourceType.php +++ b/application/src/Form/NameSourceType.php @@ -2,9 +2,23 @@ namespace App\Form; -/** - * @author kevinfrantz - */ -class NameSourceType +use App\Entity\User; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\Extension\Core\Type\TextType; + +class NameSourceType extends AbstractType { + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('name', TextType::class); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); + } } diff --git a/application/src/Form/UserSourceType.php b/application/src/Form/UserSourceType.php index 9fcd410..21f0127 100644 --- a/application/src/Form/UserSourceType.php +++ b/application/src/Form/UserSourceType.php @@ -1,12 +1,24 @@ add('namesource', NameSourceType::class); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class + ]); + } } +