Commit da54d1db authored by gnuget's avatar gnuget Committed by gnuget

Issue #2884595 by gnuget, kmonahan, MartinMa: Can delete user only with option...

Issue #2884595 by gnuget, kmonahan, MartinMa: Can delete user only with option "Delete the account and its content"
parent 91b846c3
......@@ -265,9 +265,30 @@ function _comment_notify_submit_user_form(array &$form, FormStateInterface $form
}
}
/**
* Implements hook_user_delete().
*/
function comment_notify_user_predelete(\Drupal\Core\Entity\EntityInterface $entity) {
// This hook is invoked when the account is deleted.
comment_notify_remove_user_settings($entity->id());
}
/**
* Implements hook_user_cancel().
*/
function comment_notify_user_cancel($edit, $account, $method) {
// This hook is invoked when the account is disabled.
comment_notify_remove_user_settings($account->id());
}
/**
* Remove the user settings of of the user with the given $uid
*
* @param int $uid
* The user id.
*/
function comment_notify_remove_user_settings($uid) {
module_load_include('inc', 'comment_notify', 'comment_notify');
comment_notify_delete_user_notification_setting($account->uid);
comment_notify_delete_user_notification_setting($uid);
}
/**
......
......@@ -242,4 +242,29 @@ class CommentNotifyUserPreferencesTest extends CommentNotifyTestBase {
}
/**
* Test that when the user account is canceled or deleted all the settings
* related with the CommentNotify module are deleted.
*/
public function testUserCancelAccount() {
$cancel_method_options = [
'user_cancel_block',
'user_cancel_block_unpublish',
'user_cancel_reassign',
];
foreach ($cancel_method_options as $cancel_method_option) {
$user = $this->drupalCreateUser($this->permissions);
comment_notify_set_user_notification_setting($user->id(), COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT);
user_cancel([], $user->id(), $cancel_method_option);
$this->assertTrue(is_null(comment_notify_get_user_notification_setting($user->id())));
}
// Delete Account.
$user = $this->drupalCreateUser($this->permissions);
comment_notify_set_user_notification_setting($user->id(), COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT);
$user->delete();
$this->assertTrue(is_null(comment_notify_get_user_notification_setting($user->id())));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment