1111use Symfony \Component \Form \Extension \Core \Type \TextType ;
1212use Symfony \Component \Form \FormBuilderInterface ;
1313use Symfony \Component \OptionsResolver \OptionsResolver ;
14+ use Symfony \Component \Validator \Constraints \AtLeastOneOf ;
15+ use Symfony \Component \Validator \Constraints \Blank ;
1416use Symfony \Component \Validator \Constraints \Length ;
1517
1618final class NodeSourceSeoType extends AbstractType
@@ -26,15 +28,35 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
2628 'data-max-length ' => 80 ,
2729 ],
2830 'constraints ' => [
29- new Length ([
30- 'max ' => 80 ,
31- ]),
31+ new Length (max: 80 ),
3232 ],
3333 ])
3434 ->add ('metaDescription ' , TextareaType::class, [
3535 'label ' => 'metaDescription ' ,
3636 'help ' => 'nodeSource.metaDescription.help ' ,
3737 'required ' => false ,
38+ 'attr ' => [
39+ 'data-max-length ' => 160 ,
40+ ],
41+ 'constraints ' => [
42+ /*
43+ * Either leave it empty (a "metaDescriptionFallback" field
44+ * then feeds the head) or write a relevant description: a
45+ * too-short meta-description is discarded at exposition
46+ * (see NodesSourcesHead), so reject it at input time
47+ * instead of silently dropping the editor's text.
48+ */
49+ new AtLeastOneOf (
50+ constraints: [
51+ new Blank (),
52+ // NodesSourcesHead discards candidates of 20 chars or
53+ // fewer (mb_strlen > 20), so require strictly more.
54+ new Length (min: 21 ),
55+ ],
56+ message: 'A meta-description should either be left empty or be longer than 20 characters to stay relevant for SEO. ' ,
57+ includeInternalMessages: false ,
58+ ),
59+ ],
3860 ])
3961 ->add ('noIndex ' , CheckboxType::class, [
4062 'label ' => 'nodeSource.noIndex ' ,
0 commit comments