← Back
Editing: ItemChoiceType.php
<?php declare(strict_types=1); namespace App\Form; use App\Entity\Item; use App\Repository\ItemRepository; use App\Service\SolutionService; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; class ItemChoiceType extends ChoiceType { public function __construct( private readonly SolutionService $solutionService, private readonly ItemRepository $itemRepository ) { parent::__construct(); } public function buildForm(FormBuilderInterface $builder, array $options): void { $items = $this->itemRepository->findBySolution($this->solutionService->getCurrent()); $itemGroups = []; foreach ($items as $item) { $groupLabel = sprintf( '%s > %s', $item->getZone()->getRoot()->getThematic()->getName(), $item->getZone()->getNom() ); $itemGroups[$groupLabel][$item->getNom()] = $item; } $options['choices'] = $itemGroups; $options['choice_value'] = fn (Item $item) => $item->getId(); parent::buildForm($builder, $options); } }
Save File
Cancel