daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Implements hook_preprocess_HOOK().
  3.  */
  4. function mymodule_preprocess_page(&$vars) {
  5.  
  6.   // Add CSRF token to page for authenticated users.  Token
  7.   // is required by rest resources on POST requests.
  8.   if ($vars['logged_in']) {
  9.  
  10.     $route = Drupal::routeMatch()->getRouteObject();
  11.     $is_admin = Drupal::service('router.admin_context')->isAdminRoute($route);
  12.  
  13.     if (!$is_admin) {
  14.       $vars['#attached']['drupalSettings']['user']['csrf'] = Drupal::csrfToken()->get(CsrfRequestHeaderAccessCheck::TOKEN_KEY);
  15.     }
  16.   }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top