diff --git a/src/Bundle/ChillPersonBundle/Controller/SocialWork/SocialIssueController.php b/src/Bundle/ChillPersonBundle/Controller/SocialWork/SocialIssueController.php index 97b85263c..769e90de7 100644 --- a/src/Bundle/ChillPersonBundle/Controller/SocialWork/SocialIssueController.php +++ b/src/Bundle/ChillPersonBundle/Controller/SocialWork/SocialIssueController.php @@ -13,10 +13,25 @@ namespace Chill\PersonBundle\Controller\SocialWork; use Chill\MainBundle\CRUD\Controller\CRUDController; use Chill\MainBundle\Pagination\PaginatorInterface; +use LogicException; +use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; class SocialIssueController extends CRUDController { + protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface + { + if ('new' === $action) { + return parent::createFormFor($action, $entity, $formClass, ['step' => 'create']); + } + + if ('edit' === $action) { + return parent::createFormFor($action, $entity, $formClass, ['step' => 'edit']); + } + + throw new LogicException('action is not supported: ' . $action); + } + protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) { $query->addOrderBy('e.ordering', 'ASC'); diff --git a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php index d8b9fdba9..0435b5573 100644 --- a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php +++ b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php @@ -36,12 +36,19 @@ class SocialIssueType extends AbstractType $builder ->add('title', TranslatableStringFormType::class, [ 'label' => 'Nom', - ]) - ->add('parent', EntityType::class, [ - 'class' => SocialIssue::class, - 'required' => false, - 'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()), - ]) + ]); + + if ('create' === $options['step']) { + $builder + ->add('parent', EntityType::class, [ + 'class' => SocialIssue::class, + 'required' => false, + 'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()), + 'mapped' => 'create' === $options['step'], + ]); + } + + $builder ->add('ordering', NumberType::class, [ 'required' => true, 'scale' => 6, @@ -55,5 +62,8 @@ class SocialIssueType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('class', SocialIssue::class); + + $resolver->setRequired('step') + ->setAllowedValues('step', ['create', 'edit']); } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/SocialWork/SocialIssue/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/SocialWork/SocialIssue/edit.html.twig index ffad69128..34c524132 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/SocialWork/SocialIssue/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/SocialWork/SocialIssue/edit.html.twig @@ -8,15 +8,19 @@ {% embed '@ChillMain/CRUD/_edit_content.html.twig' %} {% block crud_content_form_rows %} - {% for f in form %} - {% if f.vars.name == 'parent' %} - {{ form_row(f, { 'attr':{'disabled':'disabled'}}) }} - {% else %} - {{ form_row(f) }} - {% endif %} - {% endfor %} + {{ form_row(form.title) }} +
+ +
+ {{ entity.parent|chill_entity_render_box }} +
+
+ {{ form_row(form.ordering) }} + {{ form_row(form.desactivationDate) }} {% endblock crud_content_form_rows %} {% block content_form_actions_save_and_show %}{% endblock %} {% endembed %} -{% endblock admin_content %} \ No newline at end of file +{% endblock admin_content %}