function user_cancel_url

Same name in other branches
  1. 7.x modules/user/user.module \user_cancel_url()
  2. 8.9.x core/modules/user/user.module \user_cancel_url()
  3. 10 core/modules/user/user.module \user_cancel_url()
  4. 11.x core/modules/user/user.module \user_cancel_url()

Generates a URL to confirm an account cancellation request.

Parameters

\Drupal\user\UserInterface $account: The user account object.

array $options: (optional) A keyed array of settings. Supported options are:

  • langcode: A language code to be used when generating locale-sensitive URLs. If langcode is NULL the users preferred language is used.

Return value

string A unique URL that may be used to confirm the cancellation of the user account.

See also

user_mail_tokens()

\Drupal\user\Controller\UserController::confirmCancel()

2 calls to user_cancel_url()
UserTokenReplaceTest::testUserTokenReplacement in core/modules/user/tests/src/Functional/UserTokenReplaceTest.php
Creates a user, then tests the tokens generated from it.
user_mail_tokens in core/modules/user/user.module
Token callback to add unsafe tokens for user mails.

File

core/modules/user/user.module, line 556

Code

function user_cancel_url(UserInterface $account, $options = []) {
    $timestamp = \Drupal::time()->getRequestTime();
    $langcode = $options['langcode'] ?? $account->getPreferredLangcode();
    $url_options = [
        'absolute' => TRUE,
        'language' => \Drupal::languageManager()->getLanguage($langcode),
    ];
    return Url::fromRoute('user.cancel_confirm', [
        'user' => $account->id(),
        'timestamp' => $timestamp,
        'hashed_pass' => user_pass_rehash($account, $timestamp),
    ], $url_options)
        ->toString();
}

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