Page block validators¶
Validators check values passed to Page block attributes. The following block validators are available:
required
- checks whether the attribute is providedregexp
- validates attribute according to the provided regular expressionnot_blank
- checks whether the attribute is not left emptynot_blank_richtext
- checks whether arichtext
attribute is not left emptycontent_type
- checks whether the selected Content Types match the provided valuescontent_container
- checks whether the selected Content item is a container
Note
Do not use the required
and not_blank
validators for richtext
attributes.
Instead, use not_blank_richtext
.
For each validator you can provide a message that displays in the Page Builder when an attribute field does not fulfil the criteria.
Additionally, for some validators you can provide settings in the options
key, for example:
1 2 3 4 5 6 7 8 |
|
Custom validators¶
You can create Page block attributes with custom validators.
The following example shows how to create a validator which requires that string attributes contain only alphanumerical characters.
First, create classes that support your intended method of validation.
For example, in src/Validator
, create an AlphaOnly.php
file:
1 2 3 4 5 6 7 8 9 10 |
|
In src/Validator
, create an AlphaOnlyValidator.php
class that performs the validation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Then, in config/packages/ibexa_page_fieldtype.yaml
enable the new validator in Page Builder:
1 2 3 |
|
Finally, add the validator to one of your block attributes in config/packages/ibexam_page_fieldtype.yaml
, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|