Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Save Post variable in Drupal 8 Session an make available globally

I´m trying now for days saving data in a session to use for view contextual filter etc.

The user should select something (1,2,3,4) from a dropdown, saved in a post variable and write into session.

I tried several methods, but none is working.

$tempstore = \Drupal::service('user.private_tempstore')->get('mymodule_name');
$tempstore->set('my_variable_name', $some_data);

from another post, put in a module ending in an

"Fatal error: Call to a member function getSession() on null in /usr/www/users/smplce/nordisch/core/modules/user/src/PrivateTempStore.php on line 210"

Putting this in a module:

$_SESSION['area_session']['area'] = "test";

Is not causing an error, but trying to output in page.html.twig like this:

{{ area_session.area }}

It's doing nothing.

Please help me, I´m not really a programmer but want to solve this problem.

Thanks in advance!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In Drupal 7, you would access GET, POST, SERVER and COOKIE variables using the PHP super-globals $_GET, $_POST, $_SERVER and $_COOKIE.

Examples: -> Drupal 7:

$query = $_GET['q']; // query string param
$myparam = $_POST['myparam']; // form param
$request_method = $_SERVER['REQUEST_METHOD']; // server variable
$mycookie = $_COOKIE['mycookie']; // cookie

In Drupal 8, you need to use the Symfony Request object.

->Drupal 8:

$query = \Drupal::request()->query->get('q'); // query string param
$name = \Drupal::request()->request->get('name'); // form param
$request_method = \Drupal::request()->server->get('REQUEST_METHOD'); // server variable
$mycookie = \Drupal::request()->cookies->get('mycookie'); // cookie
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!