function hook_user_cancel_methods_alter

Same name in other branches
  1. 7.x modules/user/user.api.php \hook_user_cancel_methods_alter()
  2. 9 core/modules/user/user.api.php \hook_user_cancel_methods_alter()
  3. 8.9.x core/modules/user/user.api.php \hook_user_cancel_methods_alter()
  4. 11.x core/modules/user/user.api.php \hook_user_cancel_methods_alter()

Modify account cancellation methods.

By implementing this hook, modules are able to add, customize, or remove account cancellation methods. All defined methods are turned into radio button form elements by user_cancel_methods() after this hook is invoked. The following properties can be defined for each method:

  • title: The radio button's title.
  • description: (optional) A description to display on the confirmation form if the user is not allowed to select the account cancellation method. The description is NOT used for the radio button, but instead should provide additional explanation to the user seeking to cancel their account.
  • access: (optional) A boolean value indicating whether the user can access a method. If 'access' is defined, the method cannot be configured as default method.

Parameters

array $methods: An array containing user account cancellation methods, keyed by method id.

See also

user_cancel_methods()

\Drupal\user\Form\UserCancelForm

Related topics

File

core/modules/user/user.api.php, line 93

Code

function hook_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['my_module_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'),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.