You are here

public static function Drupal::csrfToken in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal.php \Drupal::csrfToken()
  2. 9 core/lib/Drupal.php \Drupal::csrfToken()

Returns the CSRF token manager service.

The generated token is based on the session ID of the current user. Normally, anonymous users do not have a session, so the generated token will be different on every page request. To generate a token for users without a session, manually start a session prior to calling this function.

Return value

\Drupal\Core\Access\CsrfTokenGenerator The CSRF token manager.

See also

\Drupal\Core\Session\SessionManager::start()

7 calls to Drupal::csrfToken()
DrupalMedia::getConfig in core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalMedia.php
DrupalTest::testCsrfToken in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the csrfToken() method.
Media::getDynamicPluginConfig in core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Media.php
MediaFilterController::checkCsrf in core/modules/media/src/Controller/MediaFilterController.php
Throws an AccessDeniedHttpException if the request fails CSRF validation.
QuickEditController::checkCsrf in core/modules/quickedit/src/QuickEditController.php
Throws an AccessDeniedHttpException if the request fails CSRF validation.

... See full list

File

core/lib/Drupal.php, line 609

Class

Drupal
Static Service Container wrapper.

Code

public static function csrfToken() {
  return static::getContainer()
    ->get('csrf_token');
}