- Issue created by @ttesteve
- Status changed to Needs review
over 1 year ago 10:00am 18 July 2023 - 🇦🇺Australia darvanen Sydney, Australia
There sure is, two of them ;)
Since you're working with a custom entity I would advise the first method - add a constraint to the field definition:
$fields['booking_email_address']->addConstraint('AdvancedEmailValidation');
Or if you're adjusting an existing entity you can see how the module does that in \advanced_email_validation_entity_base_field_info_alter.
If you want to adjust the validation settings then I would clone or extend the existing Validation and Validator to make your own that inject the desired settings into \Drupal\advanced_email_validation\AdvancedEmailValidator::validate as the second argument.
...
If you want to do it in the form you'll want to add the call inside the
validateForm
method.You can borrow and adjust code from \Drupal\advanced_email_validation\Plugin\Validation\Constraint\AdvancedEmailValidationValidator.
Again if you want to override the global settings you can pass new settings in to \Drupal\advanced_email_validation\AdvancedEmailValidator::validate as the second argument.
...
Do let me know how you go. If you get stuck you can find me on Drupal Slack as @darvanen, usually in #australia-nz and mainly during AEST business hours.
- 🇬🇧United Kingdom ttesteve
Hi @darvanen!
Thanks so much for the quick reply on this! I'll take a look at those notes and see which method is best to apply to my own entity. Really appreciate the offer of the extra support too - I'll shout up if I get stuck!
Cheers,
Steve - 🇦🇺Australia darvanen Sydney, Australia
@ttesteve how did you go? Can we mark this issue as fixed?
- Status changed to Fixed
over 1 year ago 1:53am 6 August 2023 - 🇦🇺Australia darvanen Sydney, Australia
Just doing some tidying. Since there's no response here I'm going to assume this is sorted and close it. Please feel free to reopen if you need more support.
- 🇦🇺Australia darvanen Sydney, Australia
forgot to credit myself, did the main response on work time.
Automatically closed - issue fixed for 2 weeks with no activity.