You are here

class ConfigStorage in Checklist API 8

Provides config-based checklist progress storage.

Hierarchy

Expanded class hierarchy of ConfigStorage

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

File

src/Storage/ConfigStorage.php, line 10

Namespace

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

  /**
   * The configuration key for saved progress.
   */
  const CONFIG_KEY = 'progress';

  /**
   * The config object.
   *
   * @var \Drupal\Core\Config\Config|null
   */
  private $config;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  private $configFactory;

  /**
   * Constructs a class instance.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function getSavedProgress() {
    return $this
      ->getConfig()
      ->get(self::CONFIG_KEY);
  }

  /**
   * {@inheritdoc}
   */
  public function setSavedProgress(array $progress) {
    $this
      ->getConfig()
      ->set(self::CONFIG_KEY, $progress)
      ->save();
  }

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

  /**
   * Gets the config object.
   *
   * @return \Drupal\Core\Config\Config
   *   Returns the config object.
   */
  private function getConfig() {
    if (empty($this->config)) {
      $this->config = $this->configFactory
        ->getEditable("checklistapi.progress.{$this->getChecklistId()}");
    }
    return $this->config;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigStorage::$config private property The config object.
ConfigStorage::$configFactory private property The config factory.
ConfigStorage::CONFIG_KEY constant The configuration key for saved progress.
ConfigStorage::deleteSavedProgress public function Deletes the saved checklist progress. Overrides StorageInterface::deleteSavedProgress
ConfigStorage::getConfig private function Gets the config object.
ConfigStorage::getSavedProgress public function Gets the saved checklist progress. Overrides StorageInterface::getSavedProgress
ConfigStorage::setSavedProgress public function Sets the saved checklist progress. Overrides StorageInterface::setSavedProgress
ConfigStorage::__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