Problem/Motivation
The core mail validator service directly uses \Egulias\MailValidator\MailValidator class, without enforcing a specific interface to generalize the behaviour of such a service.
If you want to replace that service, you don't have a reference interface, you have to make sure you match exactly what the original MailValidator exposed if you don't want to break code using the mail validator service.
Use case for replacing the service:
The e-mail validator service does not only check syntax but also that the domain exists. Yo can go a step further and also attempt delivery to see if the account effectively exists. I already have this in contrib email validator module, but it's prompt to break due to lack of contract through an interface.
Other issues:
Egulias EmailValidator has changed its interface in version 2. Proxying it would provide backward compatibility.
Proposed resolution
Introduce a new interface to define what the mail validator service should look like, and make a bridge class to the Egulias implementation that implements that interface.
Remaining tasks
Doit.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | 2749873-43-2.patch | 7.73 KB | naveenvalecha |
| #43 | 2749873-43.patch | 7.25 KB | naveenvalecha |
| #38 | interdiff-2749873-29-38.txt | 1.48 KB | naveenvalecha |
| #38 | interdiff-2749873-29-38-2.txt | 1.96 KB | naveenvalecha |
Comments
Comment #2
dawehnerWhy do you need an alternative implementation in the first place? Aren't emails a standard so one reference implementation should be enough? I'm just trying to be curious here.
Comment #3
dawehnerThe alternative way would be to add an interface upstream, any reason that we have to do that in Drupal itself?
Comment #4
cilefen commentedWhy is this Major?
Comment #5
david_garcia commentedThe e-mail validator service does not only check syntax but also that the domain exists. Yo can go a step further and also attempt delivery to see if the account effectively exists. I already have this in contrib email validator module, but it's prompt to break due to lack of contract through an interface.
Comment #6
cilefen commentedNo, it does not. DNS check is false by default.
This may help https://github.com/egulias/EmailValidator/pull/119
Comment #7
cilefen commented#2755401: Upgrade EmailValidator to 2.x
Comment #8
cilefen commentedThe EmailValidator 2.x interface breaks existing implementations which is a +1 for this issue.
Comment #9
cilefen commentedAlso interesting is that Symfony maintains its own interface in the form of Symfony\Component\Validator\Constraints\EmailValidator (part of its family of validators), which Drupal uses in some situations and the email.validator service in others.
Comment #10
cilefen commented@david_garcia There is a question on github about a new interface in version 2.
Comment #11
cilefen commentedI postponed #2755401: Upgrade EmailValidator to 2.x on this.
Comment #12
cilefen commentedThis should match the current core service.
Comment #14
cilefen commentedComment #17
cilefen commentedWe are going to need something like this as a BC layer to move to 2.x of EmailValidator.
Comment #18
dawehnerWhat about using "Valides email addresses using the egulias\EmailValidator" library or something like that?
Let's use the FQCN
Nitpick: Let's kill that, it is not longer needed.
Comment #20
cilefen commentedComment #21
markdorisonPatch re-rolled.
Comment #22
dawehnerComment #23
cilefen commentedComment #24
naveenvalechaThanks great work!
What this is for ? if not needed. remove it.
"Validates an email address."
Comment #25
mohit_aghera commentedUpdating patch as it was not getting applied to recent 8.3.x branch.
Fixing suggestions mentioned by @naveenvalecha
Comment #27
mohit_aghera commentedThere are some random failures in ArgumentPlaceholderUpdatePathTest, which doesn't seems relevant to this patch.
Any help or suggestions are appreciated.
Comment #29
mohit_aghera commentedStraight re-roll of previous patch.
Comment #30
naveenvalechaThanks!
Comment #31
catchThe patch looks OK to me, but it needs a change record.
Comment #32
naveenvalechaAdded draft CR https://www.drupal.org/node/2886353 .however, I felt that it needs more finishing before gets published. Back to RTBC.
//Naveen
Comment #33
dawehnerWon't this break now if anyone typehints the validator via the class? I fear what you want to do is this instead:
Comment #34
tstoecklerI think @dawehner is right, moving back to needs work.
Comment #35
cilefen commentedAlso think about #2755401: Upgrade EmailValidator to 2.x.
Comment #36
naveenvalecha@cilefen,
The current issue will open the way for #2755401: Upgrade EmailValidator to 2.x once the current issue will lands.
Assigned to me for #33
Question:
Do we require any empty hook_update_n or hook_post_update_name as we're adding a new service here?
//Naveen
Comment #37
cilefen commentedWill it? If memory serves, emailvalidator has a new interface.
Comment #38
naveenvalechaAttached two patches:
2749873-38.patch: This accommodated #33. As we're extending the OldEmailValidator so we don't need the isvalid function in the new service now, we could use the existing one.
2749873-38-2.patch: 2749873-38.patch + It includes an empty hook_update_n to ensure the container is actually rebuild.
Edit:
#37, Not sure about it, However, added two patches one with empty hook_update_n and other without it.
//Naveen
Comment #41
dawehnerYou miss the call to
parent::__construct()Comment #42
cilefen commentedWhatever we do here must be compatible with upgrading the library. And I'm not sure it's possible in a simple way. We may be forced to deprecate the current service and introduce a new one.
Comment #43
naveenvalecha#41,
Addressed.
#42,
you are right Chris, it does not look that we could upgrade without the BC break. I have updated the patch there with the interdiff from 2749873-43-2.patch
//Naveen
Comment #44
cilefen commentedI suggest we close this in favor of #2755401: Upgrade EmailValidator to 2.x.
Comment #48
alexpott@cilefen I agree... I'll add the people who worked on this to the credits on the other issue.