--- /dev/null
+/**
+ * Implements hook_user_cancel_methods_alter().
+ */
+function {{ machine_name }}_user_cancel_methods_alter(&$methods) {
+ $account = \Drupal::currentUser();
+ // Limit access to disable account and unpublish content method.
+ $methods['user_cancel_block_unpublish']['access'] = $account->hasPermission('administer site configuration');
+
+ // Remove the content re-assigning method.
+ unset($methods['user_cancel_reassign']);
+
+ // Add a custom zero-out method.
+ $methods['mymodule_zero_out'] = [
+ 'title' => t('Delete the account and remove all content.'),
+ 'description' => t('All your content will be replaced by empty strings.'),
+ // access should be used for administrative methods only.
+ 'access' => $account->hasPermission('access zero-out account cancellation method'),
+ ];
+}