Skip to content

Commit

Permalink
Merge pull request crf-devs#369 from crf-devs/fix-mission-type-array-…
Browse files Browse the repository at this point in the history
…values

Fix mission type array values
  • Loading branch information
mRoca authored May 3, 2020
2 parents 6fa9d1d + 91fdfe5 commit aa86c94
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Form/Type/MissionTypeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MissionTypeType extends AbstractType
Expand Down Expand Up @@ -39,6 +41,24 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'organization.assets',
])
;

$builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'handleJsonArray']);
}

public static function handleJsonArray(FormEvent $event): void
{
$data = $event->getData();

// Can be a json object with numeric keys.
if (!empty($data['userSkillsRequirement'])) {
$data['userSkillsRequirement'] = array_values($data['userSkillsRequirement']);
}

if (!empty($data['assetTypesRequirement'])) {
$data['assetTypesRequirement'] = array_values($data['assetTypesRequirement']);
}

$event->setData($data);
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down

0 comments on commit aa86c94

Please sign in to comment.