You are here

public function SessionTestController::setSession in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php \Drupal\session_test\Controller\SessionTestController::setSession()

Sets a test value on the session.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

string $test_value: A value to set on the session.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A response object containing the session values and the user ID.

1 string reference to 'SessionTestController::setSession'
session_test.routing.yml in core/modules/system/tests/modules/session_test/session_test.routing.yml
core/modules/system/tests/modules/session_test/session_test.routing.yml

File

core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php, line 193

Class

SessionTestController
Controller providing page callbacks for the action admin interface.

Namespace

Drupal\session_test\Controller

Code

public function setSession(Request $request, $test_value) {
  $session = $request
    ->getSession();
  $session
    ->set('test_value', $test_value);
  return new JsonResponse([
    'session' => $session
      ->all(),
    'user' => $this
      ->currentUser()
      ->id(),
  ]);
}