diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index 1ca26ba59..ed4534492 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Controller; use Chill\PersonBundle\Form\HouseholdType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -77,10 +78,17 @@ class HouseholdController extends AbstractController // some queries $household->getMembers()->initialize(); + if ($request->query->has('edit')) { + $form = $this->createMetadataForm($household); + } else { + $form = null; + } + return $this->render('@ChillPerson/Household/members.html.twig', [ 'household' => $household, - 'positions' => $positions + 'positions' => $positions, + 'form' => NULL !== $form ? $form->createView(): $form ] ); } @@ -132,10 +140,7 @@ class HouseholdController extends AbstractController public function editHouseholdMetadata(Request $request, Household $household) { // TODO ACL - $form = $this->createForm( - HouseholdType::class, - $household - ); + $form = $this->createMetadataForm($household); $form->handleRequest($request); @@ -154,4 +159,22 @@ class HouseholdController extends AbstractController 'form' => $form->createView() ]); } + + private function createMetadataForm(Household $household): FormInterface + { + $form = $this->createForm( + HouseholdType::class, + $household, + [ + 'action' => $this->generateUrl( + 'chill_person_household_members_metadata_edit', + [ + 'household_id' => $household->getId() + ] + ) + ] + ); + + return $form; + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 99dc0cb01..f3214fc98 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -10,6 +10,7 @@ use Symfony\Component\Serializer\Annotation as Serializer; use Chill\MainBundle\Entity\Address; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder; +use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; /** * @ORM\Entity @@ -52,9 +53,9 @@ class Household private Collection $members; /** - * @ORM\Column(type="text", name="comment_members", options={"default": ""}) + * @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_") */ - private string $commentMembers = ""; + private CommentEmbeddable $commentMembers; /** * @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false}) @@ -70,6 +71,7 @@ class Household { $this->addresses = new ArrayCollection(); $this->members = new ArrayCollection(); + $this->commentMembers = new CommentEmbeddable(); } public function getId(): ?int @@ -221,12 +223,12 @@ class Household return $this; } - public function getCommentMembers(): ?string + public function getCommentMembers(): CommentEmbeddable { return $this->commentMembers; } - public function setCommentMembers(string $commentMembers): self + public function setCommentMembers(CommentEmbeddable $commentMembers): self { $this->commentMembers = $commentMembers; diff --git a/src/Bundle/ChillPersonBundle/Form/HouseholdType.php b/src/Bundle/ChillPersonBundle/Form/HouseholdType.php index b49ed8e8e..999e2ff79 100644 --- a/src/Bundle/ChillPersonBundle/Form/HouseholdType.php +++ b/src/Bundle/ChillPersonBundle/Form/HouseholdType.php @@ -3,7 +3,7 @@ namespace Chill\PersonBundle\Form; use Chill\MainBundle\Form\Type\ChillDateType; -use Chill\MainBundle\Form\Type\ChillTextareaType; +use Chill\MainBundle\Form\Type\CommentType; use Chill\PersonBundle\Entity\Household\Household; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\AbstractType; @@ -15,7 +15,7 @@ class HouseholdType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('commentMembers', ChillTextareaType::class, [ + ->add('commentMembers', CommentType::class, [ 'label' => 'household.comment_membership', 'required' => false ]) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig index 6c001f5fb..e586f3543 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig @@ -5,18 +5,58 @@ {% block content %}
- {{ household.commentMembers|chill_markdown_to_html }} --{% endif %} +{% if form is not null %} + {{ form_start(form) }} -{% if household.waitingForBirth %} - {% if household.waitingForBirthDate is not null %} - {{ 'household.Expecting for birth on date'|trans({ 'date': household.waitingForBirthDate|format_date('long') }) }} - {% else %} - {{ 'household.Expecting for birth'|trans }} + {{ form_row(form.commentMembers) }} + +
+ {{ 'household.Any expecting birth'|trans }} +
+ {% endif %} + + + {% endif %} {% for p in positions %} @@ -153,14 +193,6 @@ {% endfor %}