function Drupal::state

Same name and namespace in other branches
  1. 9 core/lib/Drupal.php \Drupal::state()
  2. 8.9.x core/lib/Drupal.php \Drupal::state()
  3. 10 core/lib/Drupal.php \Drupal::state()

Returns the state storage service.

Use this to store machine-generated data, local to a specific environment that does not need deploying and does not need human editing; for example, the last time cron was run. Data which needs to be edited by humans and needs to be the same across development, production, etc. environments (for example, the system maintenance message) should use \Drupal::config() instead.

Return value

\Drupal\Core\State\StateInterface

25 calls to Drupal::state()
batch_test_stack in core/modules/system/tests/modules/batch_test/batch_test.module
Helper function: Stores or retrieves traced execution data.
CronQueueTestDeriverQueue::processItem in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestDeriverQueue.php
CronQueueTestException::processItem in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestException.php
CronQueueTestLeaseTime::processItem in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestLeaseTime.php
CronQueueTestRequeueException::processItem in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestRequeueException.php

... See full list

File

core/lib/Drupal.php, line 480

Class

Drupal
Static Service Container wrapper.

Code

public static function state() {
    return static::getContainer()->get('state');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.