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
|
// Validate teamer data to show missing data right away
|
||||||
$errors = $this->validator->validate($teamer, null, ['profile_preflight']);
|
$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);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ class SkillsController extends AbstractController
|
|||||||
$selectableJobProfiles[$profile->getId()] = $requiredTrainingsSatisfied && $requiredLicensesSatisfied;
|
$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);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class TeamerJobProfileType extends AbstractType
|
|||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
{
|
{
|
||||||
$selectableProfiles = $options['selectable_job_profiles'];
|
|
||||||
$builder
|
$builder
|
||||||
->add('jobProfiles', EntityType::class, [
|
->add('jobProfiles', EntityType::class, [
|
||||||
'label' => false,
|
'label' => false,
|
||||||
@@ -43,8 +42,12 @@ class TeamerJobProfileType extends AbstractType
|
|||||||
return $label;
|
return $label;
|
||||||
},
|
},
|
||||||
// Set disabled attribute on profiles that require a training or licenses the teamer doesn‘t have
|
// 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) {
|
// unless in admin mode
|
||||||
if (true === $selectableProfiles[$choice->getId()]) {
|
'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 [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +83,7 @@ class TeamerJobProfileType extends AbstractType
|
|||||||
'data_class' => Teamer::class,
|
'data_class' => Teamer::class,
|
||||||
'job_profiles' => [],
|
'job_profiles' => [],
|
||||||
'selectable_job_profiles' => [],
|
'selectable_job_profiles' => [],
|
||||||
|
'admin_mode' => false,
|
||||||
'anti_xss' => true,
|
'anti_xss' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user