Skip to content

Commit ebf5f11

Browse files
authored
Merge pull request #63 from sherlockode/fix/question-translation-type-constraints
Fix question translation type constraints
2 parents b0e9014 + 474f6f7 commit ebf5f11

1 file changed

Lines changed: 23 additions & 26 deletions

File tree

src/Form/Type/QuestionTranslationType.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,39 @@ class QuestionTranslationType extends AbstractResourceType
2121
*/
2222
public function buildForm(FormBuilderInterface $builder, array $options)
2323
{
24+
$questionConstraints = [new Length(min: 2, max: 255, groups: ['sylius'])];
25+
$answerConstraints = [new CKEditorLength(min: 2, groups: ['sylius'])];
26+
2427
$builder
2528
->add('question', TextType::class, [
2629
'label' => 'sherlockode_sylius_faq.ui.question.question',
27-
'constraints' => [
28-
new Length(min: 2, max: 255, groups: ['sylius'])
29-
],
30+
'constraints' => $questionConstraints,
3031
])
3132
->add('answer', CKEditorType::class, [
3233
'label' => 'sherlockode_sylius_faq.ui.question.answer',
33-
'constraints' => [
34-
new CKEditorLength(min: 2, groups: ['sylius'])
35-
],
34+
'constraints' => $answerConstraints,
3635
])
3736
;
3837

39-
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
40-
$data = $event->getData();
41-
if ('' !== $data['question'] || '' !== $data['answer']) {
42-
$event->getForm()
43-
->add('question', TextType::class, [
44-
'label' => 'sherlockode_sylius_faq.ui.question.question',
45-
'constraints' => [
46-
new NotBlank(groups: ['sylius']),
47-
new Length(min: 2, max: 255, groups: ['sylius']),
48-
],
49-
])
50-
->add('answer', CKEditorType::class, [
51-
'label' => 'sherlockode_sylius_faq.ui.question.answer',
52-
'constraints' => [
53-
new NotBlank(groups: ['sylius']),
54-
new CKEditorLength(min: 8, groups: ['sylius'])
55-
],
56-
])
57-
;
38+
$builder->addEventListener(
39+
FormEvents::PRE_SUBMIT,
40+
function (FormEvent $event) use ($questionConstraints, $answerConstraints)
41+
{
42+
$data = $event->getData();
43+
if ('' !== $data['question'] || '' !== $data['answer']) {
44+
$event->getForm()
45+
->add('question', TextType::class, [
46+
'label' => 'sherlockode_sylius_faq.ui.question.question',
47+
'constraints' => array_merge([new NotBlank(groups: ['sylius'])], $questionConstraints)
48+
])
49+
->add('answer', CKEditorType::class, [
50+
'label' => 'sherlockode_sylius_faq.ui.question.answer',
51+
'constraints' => array_merge([new NotBlank(groups: ['sylius'])], $answerConstraints)
52+
])
53+
;
54+
}
5855
}
59-
});
56+
);
6057
}
6158

6259
/**

0 commit comments

Comments
 (0)