mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Restrict user fields in UserGroupType based on user jobs.
Refactored the form to conditionally add 'users' and 'adminUsers' fields only if the UserGroup does not have associated user jobs. This ensures data consistency and adjusts the form behavior dynamically based on the entity state.
This commit is contained in:
parent
fb1c34f9c1
commit
e933f3e781
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Form;
|
namespace Chill\MainBundle\Form;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
@ -23,6 +24,9 @@ class UserGroupType extends AbstractType
|
|||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
/** @var UserGroup $userGroup */
|
||||||
|
$userGroup = $options['data'];
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('label', TranslatableStringFormType::class, [
|
->add('label', TranslatableStringFormType::class, [
|
||||||
'label' => 'user_group.Label',
|
'label' => 'user_group.Label',
|
||||||
@ -46,20 +50,25 @@ class UserGroupType extends AbstractType
|
|||||||
'help' => 'user_group.ExcludeKeyHelp',
|
'help' => 'user_group.ExcludeKeyHelp',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'empty_data' => '',
|
'empty_data' => '',
|
||||||
])
|
]);
|
||||||
->add('users', PickUserDynamicType::class, [
|
|
||||||
'label' => 'user_group.Users',
|
if (!$userGroup->hasUserJob()) {
|
||||||
'multiple' => true,
|
$builder
|
||||||
'required' => false,
|
->add('users', PickUserDynamicType::class, [
|
||||||
'empty_data' => [],
|
'label' => 'user_group.Users',
|
||||||
])
|
'multiple' => true,
|
||||||
->add('adminUsers', PickUserDynamicType::class, [
|
'required' => false,
|
||||||
'label' => 'user_group.adminUsers',
|
'empty_data' => [],
|
||||||
'multiple' => true,
|
])
|
||||||
'required' => false,
|
->add('adminUsers', PickUserDynamicType::class, [
|
||||||
'empty_data' => [],
|
'label' => 'user_group.adminUsers',
|
||||||
'help' => 'user_group.adminUsersHelp',
|
'multiple' => true,
|
||||||
])
|
'required' => false,
|
||||||
;
|
'empty_data' => [],
|
||||||
|
'help' => 'user_group.adminUsersHelp',
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user