mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fixed: [social issue][admin] do not remove the parent when editing a social issue
https://gitlab.com/Chill-Projet/chill-bundles/-/issues/46
This commit is contained in:
parent
6bba6f68b3
commit
b2dec3e587
@ -13,10 +13,25 @@ namespace Chill\PersonBundle\Controller\SocialWork;
|
|||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use LogicException;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class SocialIssueController extends CRUDController
|
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)
|
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
|
||||||
{
|
{
|
||||||
$query->addOrderBy('e.ordering', 'ASC');
|
$query->addOrderBy('e.ordering', 'ASC');
|
||||||
|
@ -36,12 +36,19 @@ class SocialIssueType extends AbstractType
|
|||||||
$builder
|
$builder
|
||||||
->add('title', TranslatableStringFormType::class, [
|
->add('title', TranslatableStringFormType::class, [
|
||||||
'label' => 'Nom',
|
'label' => 'Nom',
|
||||||
])
|
]);
|
||||||
->add('parent', EntityType::class, [
|
|
||||||
'class' => SocialIssue::class,
|
if ('create' === $options['step']) {
|
||||||
'required' => false,
|
$builder
|
||||||
'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()),
|
->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, [
|
->add('ordering', NumberType::class, [
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'scale' => 6,
|
'scale' => 6,
|
||||||
@ -55,5 +62,8 @@ class SocialIssueType extends AbstractType
|
|||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setDefault('class', SocialIssue::class);
|
$resolver->setDefault('class', SocialIssue::class);
|
||||||
|
|
||||||
|
$resolver->setRequired('step')
|
||||||
|
->setAllowedValues('step', ['create', 'edit']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,19 @@
|
|||||||
{% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
|
{% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
|
||||||
|
|
||||||
{% block crud_content_form_rows %}
|
{% block crud_content_form_rows %}
|
||||||
{% for f in form %}
|
{{ form_row(form.title) }}
|
||||||
{% if f.vars.name == 'parent' %}
|
<div class="mb-3 row">
|
||||||
{{ form_row(f, { 'attr':{'disabled':'disabled'}}) }}
|
<label class="col-form-label col-sm-4">
|
||||||
{% else %}
|
{{ 'Parent'|trans }}
|
||||||
{{ form_row(f) }}
|
</label>
|
||||||
{% endif %}
|
<div class="col-sm-8">
|
||||||
{% endfor %}
|
{{ entity.parent|chill_entity_render_box }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ form_row(form.ordering) }}
|
||||||
|
{{ form_row(form.desactivationDate) }}
|
||||||
{% endblock crud_content_form_rows %}
|
{% endblock crud_content_form_rows %}
|
||||||
|
|
||||||
{% block content_form_actions_save_and_show %}{% endblock %}
|
{% block content_form_actions_save_and_show %}{% endblock %}
|
||||||
{% endembed %}
|
{% endembed %}
|
||||||
{% endblock admin_content %}
|
{% endblock admin_content %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user