TempStore API: A key-value storage to keep temporary data (private or shared) across page requests.
- Set the value using the Drupal service private_tempstore:
$tempstore = \Drupal::service('user.private_tempstore')->get('module_name'); $tempstore->set('foo', 'bar');
- Get value using the Drupal service private_tempstore:
$tempstore = \Drupal::service('user.private_tempstore')->get('module_name'); $myKey = $tempstore->get('foo');
- By default, it keeps the value stored for a week, while you can also delete the value using the delete function.
$tempstore = \Drupal::service('user.private_tempstore')->get('module_name'); $store->delete('foo');
- Log in to post comments