Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disable required constraint for freetext and headline field #380

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Form/Type/DynamicFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Sulu\Bundle\FormBundle\Dynamic\Checksum;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypePool;
use Sulu\Bundle\FormBundle\Dynamic\Types\FreeTextType;
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
use Sulu\Bundle\FormBundle\Dynamic\Types\HeadlineType;
use Sulu\Bundle\FormBundle\Entity\Dynamic;
use Sulu\Bundle\FormBundle\Entity\Form;
use Sulu\Bundle\FormBundle\Exception\FormNotFoundException;
Expand Down Expand Up @@ -113,12 +115,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$options['attr']['placeholder'] = $placeholder;
}

$formFieldType = $this->typePool->get($field->getType());

// required
if ($field->getRequired()) {
if (
!$formFieldType instanceof FreeTextType
&& !$formFieldType instanceof HeadlineType
&& $field->getRequired()
) {
$options['constraints'][] = new NotBlank();
}

$this->typePool->get($field->getType())->build($builder, $field, $locale, $options);
$formFieldType->build($builder, $field, $locale, $options);
}

// Add hidden locale. (de, en, ...)
Expand Down
Loading