function search_api_saved_searches_user_update in Search API Saved Searches 8
Same name and namespace in other branches
- 7 search_api_saved_searches.module \search_api_saved_searches_user_update()
Implements hook_ENTITY_TYPE_update() for type "user".
If a user gets activated, associate saved searches with the same mail address with them.
If a user gets deactivated, disable all related saved searches.
Also, change mail address of saved searches when the user mail address changes (on behalf of the "E-mail" notification plugin).
File
- ./
search_api_saved_searches.module, line 126 - Allows visitors to bookmark searches and get notifications for new results.
Code
function search_api_saved_searches_user_update(UserInterface $account) {
$original = $account->original;
if (!$original instanceof UserInterface) {
return;
}
// For newly activated users, transfer all saved searches with their mail
// address to them.
if ($account
->isActive() && !$original
->isActive()) {
_search_api_saved_searches_claim_anonymous_searches($account);
}
// If an account gets deactivated/banned, disable all associated searches.
if (!$account
->isActive() && $original
->isActive()) {
_search_api_saved_searches_deactivate_searches($account);
}
// Addition on behalf of the "E-Mail" notification plugin: If the user's mail
// address changed, also change the mail address of the user's saved searches
// from previous (original) to current address.
if ($account
->getEmail() !== $original
->getEmail()) {
_search_api_saved_searches_adapt_mail($account, $original);
}
}