mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
WIP dynamic picking of accompanying period work
This commit is contained in:
parent
e88da74882
commit
d9acda67e3
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user