State API | Drupal 8

State API

Submitted by editor on Thu, 06/24/2021 - 10:52

State servic eallow to store variables such as state of the server temporarily or permanently

Examples:

Read
A single value.
$val = \Drupal::state()->get('key');
Multiple key/value pairs.
$pairs = \Drupal::state()->getMultiple($keys);

Write
A single value.
\Drupal::state()->set('key','value');
Multiple values.
\Drupal::state()->setMultiple($keyvalues);

Remove
\Drupal::state()->delete('key');

 

More details : https://www.drupal.org/docs/8/api/state-api/overview

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.