Problem/Motivation
Currently calling code has to do something like:
$is_registered = $host_entity->isUserRegistered($registration->getUser());
if (!$is_registered) {
$is_registered = $host_entity->isEmailRegistered($registration->getEmail());
}
This has various problems:
1. Its an unnecessary extra query
2. The methods use database queries not entity queries
3. It puts extra work on the calling code, as it has to call both isUserRegistered() and isEmailRegistered() to be thorough.
4. There are various edge cases that are easy to overlook:
-- what if because of custom logic $registration->getUser()->getEmail() !== $registration->getEmail()
-- what if the user registered previously anonymously using their email and now registers by user account. The old anon registration won't be picked up unless isEmailRegistered($user->getEmail()) is called, which might be overlooked.
-- what if the user registered previously using their account, has subsequently changed account email, and now registers by new email alone. The old registration won't be picked up even if the old email was stored in the anon_mail field.
-- what if the user has or had multiple email addresses see e.g.
https://www.drupal.org/project/alternative_user_emails β
)
Proposed resolution
Deprecate isEmailRegistered(), isEmailRegisteredInStates(), isUserRegistered(), and isUserRegisteredInStates().
Replace them with a single method:
isRegistrant(AccountInterface $account = NULL, $email = NULL, $states = []);
This would check the email, user, and all the edge cases, in a single query.
Remaining tasks
User interface changes
None.
API changes
New HostEntityInterface methods:
isRegistrant()
getRegistrationQuery()
Deprecate existing methods:
isEmailRegistered()
isUserRegistered()
isEmailRegisteredInStates()
isUserRegisteredInStates()
Data model changes
None.