feat: admin mode for teamer profile form to override disabled fields
This commit is contained in:
@@ -53,7 +53,10 @@ class IndexController extends AbstractController
|
||||
// Validate teamer data to show missing data right away
|
||||
$errors = $this->validator->validate($teamer, null, ['profile_preflight']);
|
||||
|
||||
$form = $this->createForm(TeamerProfileType::class, $teamer, ['upload_session' => $uploadSession]);
|
||||
$form = $this->createForm(TeamerProfileType::class, $teamer, [
|
||||
'upload_session' => $uploadSession,
|
||||
'admin_mode' => $this->isGranted('IS_IMPERSONATOR'),
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
@@ -59,7 +59,11 @@ class SkillsController extends AbstractController
|
||||
$selectableJobProfiles[$profile->getId()] = $requiredTrainingsSatisfied && $requiredLicensesSatisfied;
|
||||
}
|
||||
|
||||
$form = $this->createForm(TeamerJobProfileType::class, $teamer, ['job_profiles' => $jobProfiles, 'selectable_job_profiles' => $selectableJobProfiles]);
|
||||
$form = $this->createForm(TeamerJobProfileType::class, $teamer, [
|
||||
'job_profiles' => $jobProfiles,
|
||||
'selectable_job_profiles' => $selectableJobProfiles,
|
||||
'admin_mode' => $this->isGranted('IS_IMPERSONATOR'),
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
@@ -18,7 +18,6 @@ class TeamerJobProfileType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$selectableProfiles = $options['selectable_job_profiles'];
|
||||
$builder
|
||||
->add('jobProfiles', EntityType::class, [
|
||||
'label' => false,
|
||||
@@ -43,8 +42,12 @@ class TeamerJobProfileType extends AbstractType
|
||||
return $label;
|
||||
},
|
||||
// Set disabled attribute on profiles that require a training or licenses the teamer doesn‘t have
|
||||
'choice_attr' => function($choice, string $key, mixed $value) use ($selectableProfiles) {
|
||||
if (true === $selectableProfiles[$choice->getId()]) {
|
||||
// unless in admin mode
|
||||
'choice_attr' => function($choice, string $key, mixed $value) use ($options) {
|
||||
$selectableProfiles = $options['selectable_job_profiles'];
|
||||
$isAdminMode = $options['admin_mode'];
|
||||
|
||||
if (true === $isAdminMode || true === $selectableProfiles[$choice->getId()]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -80,6 +83,7 @@ class TeamerJobProfileType extends AbstractType
|
||||
'data_class' => Teamer::class,
|
||||
'job_profiles' => [],
|
||||
'selectable_job_profiles' => [],
|
||||
'admin_mode' => false,
|
||||
'anti_xss' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user