diff --git a/src/Controller/FridgeController.php b/src/Controller/FridgeController.php index 76764fb..02d8e26 100644 --- a/src/Controller/FridgeController.php +++ b/src/Controller/FridgeController.php @@ -30,10 +30,14 @@ class FridgeController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + foreach ($fridge->getProductLines() as $productLine) { + $productLine->setFridge($fridge); + $em->persist($productLine); + } $em->persist($fridge); $em->flush(); - return $this->redirectToRoute('fridge_list'); +// return $this->redirectToRoute('fridge_list'); } return $this->render('fridge/single.html.twig', [ diff --git a/src/Entity/Fridge.php b/src/Entity/Fridge.php index 50cbc88..be55499 100644 --- a/src/Entity/Fridge.php +++ b/src/Entity/Fridge.php @@ -29,6 +29,11 @@ class Fridge $this->productLines = new ArrayCollection(); } + public function __toString(): string + { + return $this->name; + } + public function getId(): ?int { return $this->id; diff --git a/src/Form/FridgeProductLineType.php b/src/Form/FridgeProductLineType.php new file mode 100644 index 0000000..88420bc --- /dev/null +++ b/src/Form/FridgeProductLineType.php @@ -0,0 +1,16 @@ +setDefaults([ + 'data_class' => FridgeProductLine::class, + ]); + } +} \ No newline at end of file diff --git a/src/Form/FridgeType.php b/src/Form/FridgeType.php index c3fee99..a02c39e 100644 --- a/src/Form/FridgeType.php +++ b/src/Form/FridgeType.php @@ -4,6 +4,7 @@ namespace App\Form; use App\Entity\Fridge; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -15,7 +16,10 @@ class FridgeType extends AbstractType $builder ->add('name') ->add('description') - ->add('productLines') + ->add('productLines', CollectionType::class, [ + 'entry_type' => FridgeProductLineType::class, + 'allow_add' => true, + ]) ->add('save', SubmitType::class) ; } diff --git a/src/Form/ProductLineType.php b/src/Form/ProductLineType.php new file mode 100644 index 0000000..407acb6 --- /dev/null +++ b/src/Form/ProductLineType.php @@ -0,0 +1,17 @@ +add('product') + ->add('count') + ; + } +} \ No newline at end of file diff --git a/templates/base/base.html.twig b/templates/base/base.html.twig index 5d41353..48d96f3 100644 --- a/templates/base/base.html.twig +++ b/templates/base/base.html.twig @@ -28,6 +28,10 @@ + {# {{ encore_entry_script_tags('app') }}#} {% endblock %} diff --git a/templates/fridge/single.html.twig b/templates/fridge/single.html.twig index 9b184eb..a4bbb12 100644 --- a/templates/fridge/single.html.twig +++ b/templates/fridge/single.html.twig @@ -2,4 +2,35 @@ {% block body %} {{ form(form) }} + +{% endblock %} + +{% block javascripts %} + {{ parent() }} + {% endblock %} \ No newline at end of file