From 894c31f09c22ca11fa4ac74995452ff4b7d093ca Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 6 Mar 2022 19:57:48 +0100 Subject: [PATCH] configure forms --- .../InterventionAdminController.php | 8 ++--- src/Entity/Intervention.php | 12 +++---- src/Entity/Tool.php | 5 +++ src/Form/InterventionType.php | 33 ++++++++++++++----- templates/admin/intervention/_form.html.twig | 13 ++++++++ translations/messages.fr.yaml | 9 +++++ 6 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 templates/admin/intervention/_form.html.twig diff --git a/src/Controller/InterventionAdminController.php b/src/Controller/InterventionAdminController.php index 565831d..f886394 100644 --- a/src/Controller/InterventionAdminController.php +++ b/src/Controller/InterventionAdminController.php @@ -122,18 +122,16 @@ class InterventionAdminController extends CrudController ->setDefaultSort('index', 'date', 'desc') + ->setView('form', 'admin/intervention/_form.html.twig') + ->setField('index', 'Establishment', Field\TextField::class, [ 'property' => 'establishment', 'sort' => ['establishment', '.establishment'], ]) - ->setField('index', 'Speaker', Field\TextField::class, [ - 'property' => 'speaker', - 'sort' => ['speaker', '.speaker'], - 'attr' => ['class' => 'col-3,'] - ]) ->setField('index', 'Date', Field\DateField::class, [ 'property' => 'date', 'sort' => ['date', '.date'], + 'attr' => ['class' => 'col-3'], ]) ->setBatchAction('index', 'delete', 'Delete', function(EntityInterface $entity, EntityManager $manager) { diff --git a/src/Entity/Intervention.php b/src/Entity/Intervention.php index 14c2ce4..3b2aeee 100644 --- a/src/Entity/Intervention.php +++ b/src/Entity/Intervention.php @@ -23,7 +23,7 @@ class Intervention implements EntityInterface /** * @ORM\ManyToMany(targetEntity=Speaker::class, inversedBy="interventions") */ - private $speaker; + private $speakers; /** * @ORM\ManyToOne(targetEntity=Establishment::class, inversedBy="interventions") @@ -82,7 +82,7 @@ class Intervention implements EntityInterface public function __construct() { - $this->speaker = new ArrayCollection(); + $this->speakers = new ArrayCollection(); $this->tools = new ArrayCollection(); } @@ -94,15 +94,15 @@ class Intervention implements EntityInterface /** * @return Collection */ - public function getSpeaker(): Collection + public function getSpeakers(): Collection { - return $this->speaker; + return $this->speakers; } public function addSpeaker(Speaker $speaker): self { - if (!$this->speaker->contains($speaker)) { - $this->speaker[] = $speaker; + if (!$this->speakers->contains($speaker)) { + $this->speakers[] = $speaker; } return $this; diff --git a/src/Entity/Tool.php b/src/Entity/Tool.php index 6a9f16b..c4a17b0 100644 --- a/src/Entity/Tool.php +++ b/src/Entity/Tool.php @@ -35,6 +35,11 @@ class Tool implements EntityInterface $this->interventions = new ArrayCollection(); } + public function __toString() + { + return $this->getLabel(); + } + public function getId(): ?int { return $this->id; diff --git a/src/Form/InterventionType.php b/src/Form/InterventionType.php index 27c520a..f0950e7 100644 --- a/src/Form/InterventionType.php +++ b/src/Form/InterventionType.php @@ -13,17 +13,34 @@ class InterventionType extends AbstractType { $builder ->add('activityReference') - ->add('date') + ->add('date', null, [ + 'html5' => true, + 'widget' => 'single_text', + ]) ->add('groups') ->add('levels') - ->add('themes') - ->add('content') - ->add('toolsDetails') - ->add('feedback') - ->add('vigilantPoints') - ->add('speaker') + ->add('themes', null, [ + 'attr' => ['rows' => 5], + ]) + ->add('content', null, [ + 'attr' => ['rows' => 7], + ]) + ->add('tools', null, [ + 'expanded' => true, + ]) + ->add('toolsDetails', null, [ + 'attr' => ['rows' => 5], + ]) + ->add('feedback', null, [ + 'attr' => ['rows' => 5], + ]) + ->add('vigilantPoints', null, [ + 'attr' => ['rows' => 5], + ]) + ->add('speakers', null, [ + 'expanded' => true, + ]) ->add('establishment') - ->add('tools') ; } diff --git a/templates/admin/intervention/_form.html.twig b/templates/admin/intervention/_form.html.twig new file mode 100644 index 0000000..e44b249 --- /dev/null +++ b/templates/admin/intervention/_form.html.twig @@ -0,0 +1,13 @@ +
+
+ {% for item in ['establishment', 'activityReference', 'date', 'groups', 'levels', 'speakers'] %} + {% include(configuration.view('form_widget', '@Core/admin/crud/_form_widget.html.twig')) with {form: form[item]} %} + {% endfor %} +
+
+ {% for item in ['themes', 'content', 'tools', 'toolsDetails', 'feedback', 'vigilantPoints'] %} + {% include(configuration.view('form_widget', '@Core/admin/crud/_form_widget.html.twig')) with {form: form[item]} %} + {% endfor %} +
+
+ diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index 58baeed..50f925e 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -2,4 +2,13 @@ "Zip code": "Code postal" "City": "Ville" "Speaker": "Intervenant⋅e" +"Speakers": "Intervenant⋅e⋅s" "Establishment": "Établissement" +"Activity reference": "Activité de référence" +"Groups": "Groupe(s)" +"Levels": "Niveau(x)" +"Themes": "Thématiques abordées" +"Tools": "Outils et supports" +"Tools details": "Détails outils et supports" +"Feedback": "Les retours des participant⋅e⋅s" +"Vigilant points": "Point(s) de vigilance observé(s) par l'intervenant⋅e"