function State::__construct

Same name in this branch
  1. 10 core/modules/workflows/src/State.php \Drupal\workflows\State::__construct()
Same name in other branches
  1. 9 core/modules/workflows/src/State.php \Drupal\workflows\State::__construct()
  2. 9 core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::__construct()
  3. 8.9.x core/modules/workflows/src/State.php \Drupal\workflows\State::__construct()
  4. 8.9.x core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::__construct()
  5. 11.x core/modules/workflows/src/State.php \Drupal\workflows\State::__construct()
  6. 11.x core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::__construct()

Constructs a State object.

Parameters

\Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory: The key value store to use.

\Drupal\Core\Cache\CacheBackendInterface $cache: The cache backend.

\Drupal\Core\Lock\LockBackendInterface $lock: The lock backend.

Overrides CacheCollector::__construct

File

core/lib/Drupal/Core/State/State.php, line 50

Class

State
Provides the state system using a key value store.

Namespace

Drupal\Core\State

Code

public function __construct(KeyValueFactoryInterface $key_value_factory, ?CacheBackendInterface $cache = NULL, ?LockBackendInterface $lock = NULL) {
    if (!$cache) {
        @trigger_error('Calling  ' . __METHOD__ . '() without the $cache argument is deprecated in drupal:10.3.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3177901', E_USER_DEPRECATED);
        $cache = \Drupal::cache('bootstrap');
    }
    if (!$lock) {
        @trigger_error('Calling  ' . __METHOD__ . '() without the $lock argument is deprecated in drupal:10.3.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/3177901', E_USER_DEPRECATED);
        $lock = \Drupal::service('lock');
    }
    parent::__construct('state', $cache, $lock);
    $this->keyValueStore = $key_value_factory->get('state');
    // For backward compatibility, allow to opt-out of state caching, if cache
    // is not explicitly enabled, flag the cache as already loaded.
    if (Settings::get('state_cache') !== TRUE) {
        $this->cacheLoaded = TRUE;
    }
}

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