summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgnuget2019-01-31 05:32:00 (GMT)
committerDavid Valdez2019-01-31 05:32:00 (GMT)
commitda54d1db75e194d02eab27615fb167b2832f6a62 (patch)
treef5d0d777723c544baa0fa9b6765cfbb638881ea3
parent91b846c3df740714def86ea088c9894eeb86b3ab (diff)
Issue #2884595 by gnuget, kmonahan, MartinMa: Can delete user only with option "Delete the account and its content"
-rw-r--r--comment_notify.module23
-rw-r--r--tests/src/Functional/CommentNotifyUserPreferencesTest.php25
2 files changed, 47 insertions, 1 deletions
diff --git a/comment_notify.module b/comment_notify.module
index 7ed8c07..7359efb 100644
--- a/comment_notify.module
+++ b/comment_notify.module
@@ -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);
}
/**
diff --git a/tests/src/Functional/CommentNotifyUserPreferencesTest.php b/tests/src/Functional/CommentNotifyUserPreferencesTest.php
index 245e1c6..5206031 100644
--- a/tests/src/Functional/CommentNotifyUserPreferencesTest.php
+++ b/tests/src/Functional/CommentNotifyUserPreferencesTest.php
@@ -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())));
+ }
+
}