public function RouteProcessorCsrf::processOutbound in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Access/RouteProcessorCsrf.php \Drupal\Core\Access\RouteProcessorCsrf::processOutbound()
- 9 core/lib/Drupal/Core/Access/RouteProcessorCsrf.php \Drupal\Core\Access\RouteProcessorCsrf::processOutbound()
File
- core/lib/Drupal/Core/Access/RouteProcessorCsrf.php, line 36
Class
- RouteProcessorCsrf
- Processes the outbound route to handle the CSRF token.
Namespace
Drupal\Core\Access
Code
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
if ($route
->hasRequirement('_csrf_token')) {
$path = ltrim($route
->getPath(), '/');
foreach ($parameters as $param => $value) {
$path = str_replace("{{$param}}", $value, $path);
}
if (!$bubbleable_metadata) {
$parameters['token'] = $this->csrfToken
->get($path);
}
else {
$placeholder = Crypt::hashBase64($path);
$placeholder_render_array = [
'#lazy_builder' => [
'route_processor_csrf:renderPlaceholderCsrfToken',
[
$path,
],
],
];
$parameters['token'] = $placeholder;
$bubbleable_metadata
->addAttachments([
'placeholders' => [
$placeholder => $placeholder_render_array,
],
]);
}
}
}