Skip to content

Commit 8687a90

Browse files
committed
feat(title): add option to make the title content required or not
1 parent da3a0c2 commit 8687a90

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Form/Type/UiElement/TitleType.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\TagType;
1919
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\TextSizeType;
2020
use Symfony\Component\Form\AbstractType;
21+
use Symfony\Component\Form\Extension\Core\Type\TextType;
2122
use Symfony\Component\Form\FormBuilderInterface;
23+
use Symfony\Component\OptionsResolver\OptionsResolver;
2224
use Symfony\Component\Validator\Constraints as Assert;
2325

2426
class TitleType extends AbstractType
@@ -29,8 +31,8 @@ class TitleType extends AbstractType
2931
public function buildForm(FormBuilderInterface $builder, array $options): void
3032
{
3133
$builder
32-
->add('content', \Symfony\Component\Form\Extension\Core\Type\TextType::class, [
33-
'required' => true,
34+
->add('content', TextType::class, [
35+
'required' => $options['required_title'] ?? false,
3436
'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.title.field.content',
3537
'constraints' => [
3638
new Assert\NotBlank([]),
@@ -51,4 +53,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5153
])
5254
;
5355
}
56+
57+
public function configureOptions(OptionsResolver $resolver): void
58+
{
59+
$resolver->setDefaults([
60+
'required_title' => true,
61+
]);
62+
}
5463
}

0 commit comments

Comments
 (0)