diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php index 321b1812a..c20340577 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php @@ -23,9 +23,10 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator) {} #[Route(path: '{_locale}/person/accompanying-period/work/{id}/assign-duplicate', name: 'chill_person_accompanying_period_work_assign_duplicate', methods: ['GET'])] - public function assignDuplicate(mixed $id, Request $request) + public function assignDuplicate(int $id, Request $request) { $acpw1= $this->accompanyingPeriodWorkRepository->find($id); + $accompanyingPeriod = $acpw1->getAccompanyingPeriod(); if (null === $acpw1) { throw $this->createNotFoundException("Accompanying period work with id {$id} not".' found on this server'); @@ -37,7 +38,7 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController 'You are not allowed to merge this accompanying period work' ); - $form = $this->createForm(FindAccompanyingPeriodWorkType::class); + $form = $this->createForm(FindAccompanyingPeriodWorkType::class, null, ['accompanyingPeriod' => $accompanyingPeriod]); $form->handleRequest($request); diff --git a/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php index 69ade244b..d38a0fbd9 100644 --- a/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php +++ b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Form; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Form\Type\PickAccompanyingPeriodWorkDynamicType; +use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; @@ -19,11 +21,28 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class FindAccompanyingPeriodWorkType extends AbstractType { + public function __construct(private readonly AccompanyingPeriodWorkRepository $repository) + { + } public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('acpw', PickAccompanyingPeriodWorkDynamicType::class) + $accompanyingPeriod = $options['accompanyingPeriod']; + $suggestedAcpw = $this->repository->findByAccompanyingPeriod($accompanyingPeriod); + + $builder + ->add('acpw', PickAccompanyingPeriodWorkDynamicType::class, [ + 'label' => 'Accompanying period work', + 'suggested' => $suggestedAcpw + ]) ->add('direction', HiddenType::class, [ 'data' => 'starting', ]); } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setRequired('accompanyingPeriod') + ->setAllowedTypes('accompanyingPeriod', AccompanyingPeriod::class); + } } diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php index 8936b41c6..d08a1c061 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php @@ -9,23 +9,30 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; class PickAccompanyingPeriodWorkDynamicType extends AbstractType { - public function __construct(private readonly DenormalizerInterface $denormalizer, private readonly SerializerInterface $serializer) {} + public function __construct(private readonly DenormalizerInterface $denormalizer, private readonly SerializerInterface $serializer, private readonly NormalizerInterface $normalizer) {} public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'accompanyingPeriodWork')); + $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'person')); } public function buildView(FormView $view, FormInterface $form, array $options) { - $view->vars['types'] = ['accompanyingPeriodWork']; + $view->vars['multiple'] = $options['multiple']; + $view->vars['types'] = ['acpw']; $view->vars['uniqid'] = uniqid('pick_acpw_dyn'); + $view->vars['suggested'] = []; $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; - $view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0'; + $view->vars['submit_on_adding_new_entity'] = false; + + foreach ($options['suggested'] as $person) { + $view->vars['suggested'][] = $this->normalizer->normalize($person, 'json', ['groups' => 'read']); + } } public function configureOptions(OptionsResolver $resolver)