1. 8.5.x core/core.api.php state_api
  2. 8.0.x core/core.api.php state_api
  3. 8.1.x core/core.api.php state_api
  4. 8.2.x core/core.api.php state_api
  5. 8.3.x core/core.api.php state_api
  6. 8.4.x core/core.api.php state_api
  7. 8.6.x core/core.api.php state_api

Information about the State API.

The State API is one of several methods in Drupal for storing information. See the Information types topic for an overview of the different types of information.

The basic entry point into the State API is \Drupal::state(), which returns an object of class \Drupal\Core\State\StateInterface. This class has methods for storing and retrieving state information; each piece of state information is associated with a string-valued key. Example:

// Get the state class.
$state = \Drupal::state();

// Find out when cron was last run; the key is 'system.cron_last'.
$time = $state

// Set the cron run time to the current request time.
  ->set('system.cron_last', REQUEST_TIME);

For more on the State API, see https://www.drupal.org/developing/api/8/state


core/core.api.php, line 176
Documentation landing page and topics, plus core library hooks.


Namesort descending Location Description
StateInterface core/lib/Drupal/Core/State/StateInterface.php Defines the interface for the state system.