You are here

class StateStorage in Checklist API 8

Provides state-based checklist progress storage.

Hierarchy

Expanded class hierarchy of StateStorage

1 string reference to 'StateStorage'
checklistapi.services.yml in ./checklistapi.services.yml
checklistapi.services.yml
1 service uses StateStorage
checklistapi_storage.state in ./checklistapi.services.yml
Drupal\checklistapi\Storage\StateStorage

File

src/Storage/StateStorage.php, line 10

Namespace

Drupal\checklistapi\Storage
View source
class StateStorage extends StorageBase {

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  private $state;

  /**
   * Constructs a class instance.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * {@inheritdoc}
   */
  public function getSavedProgress() {
    return $this->state
      ->get($this
      ->stateKey());
  }

  /**
   * {@inheritdoc}
   */
  public function setSavedProgress(array $progress) {
    $this->state
      ->set($this
      ->stateKey(), $progress);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteSavedProgress() {
    $this->state
      ->delete($this
      ->stateKey());
  }

  /**
   * Returns the state key.
   *
   * @return string
   *   The state key.
   */
  private function stateKey() {
    return 'checklistapi.progress.' . $this
      ->getChecklistId();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StateStorage::$state private property The state service.
StateStorage::deleteSavedProgress public function Deletes the saved checklist progress. Overrides StorageInterface::deleteSavedProgress
StateStorage::getSavedProgress public function Gets the saved checklist progress. Overrides StorageInterface::getSavedProgress
StateStorage::setSavedProgress public function Sets the saved checklist progress. Overrides StorageInterface::setSavedProgress
StateStorage::stateKey private function Returns the state key.
StateStorage::__construct public function Constructs a class instance.
StorageBase::$checklistId private property The checklist ID.
StorageBase::getChecklistId protected function Gets the checklist ID.
StorageBase::setChecklistId public function Sets the checklist ID. Overrides StorageInterface::setChecklistId