State.php in Key 8
File
tests/modules/key_test/src/Plugin/KeyProvider/State.php
View source
<?php
namespace Drupal\key_test\Plugin\KeyProvider;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\key\KeyInterface;
use Drupal\key\Plugin\KeyProviderBase;
use Drupal\key\Plugin\KeyProviderSettableValueInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class State extends KeyProviderBase implements KeyProviderSettableValueInterface, ContainerFactoryPluginInterface {
protected $state;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->state = $container
->get('state');
return $instance;
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'state_key' => '',
];
}
public function getKeyValue(KeyInterface $key) {
return $this->state
->get('key_test:' . $this->configuration['state_key']);
}
public function setKeyValue(KeyInterface $key, $key_value) {
return $this->state
->set('key_test:' . $this->configuration['state_key'], $key_value);
}
public function deleteKeyValue(KeyInterface $key) {
return $this->state
->delete('key_test:' . $this->configuration['state_key']);
}
}
Classes
Name |
Description |
State |
Defines a key provider that stores in memory. |