$state = \Drupal::state(); $state->set('my_key', 'my_value'); // set state $value = $state->get('my_key', 'default_value'); // get state
$data = array('foo' => 'bar', 'baz' => 'qux'); $state = \Drupal::state(); $state->set('my_data', $data); // set state $data = $state->get('my_data', array()); // get state
$state = \Drupal::state(); $state->set('my_module_config', $config); // set state $config = $state->get('my_module_config', array()); // get stateIn this example, a module's configuration values are stored in the state system using a specific key. This makes it easy to retrieve and update the configuration values. The Drupal state system is part of the core Drupal package and does not require any additional library or package.