Skip to content

Commit 18ef948

Browse files
author
roadiz-ci
committed
Merge tag v2.7.33 into develop
1 parent 8283436 commit 18ef948

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/Form/NodeSource/NodeSourceSeoType.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Symfony\Component\Form\Extension\Core\Type\TextType;
1212
use Symfony\Component\Form\FormBuilderInterface;
1313
use Symfony\Component\OptionsResolver\OptionsResolver;
14+
use Symfony\Component\Validator\Constraints\AtLeastOneOf;
15+
use Symfony\Component\Validator\Constraints\Blank;
1416
use Symfony\Component\Validator\Constraints\Length;
1517

1618
final 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

Comments
 (0)