You are here

class CheckSettings in Security Review 8

Defines the default implementation of CheckSettingsInterface.

Hierarchy

Expanded class hierarchy of CheckSettings

1 file declares its use of CheckSettings
TrustedHostSettings.php in src/CheckSettings/TrustedHostSettings.php

File

src/CheckSettings.php, line 10

Namespace

Drupal\security_review
View source
class CheckSettings implements CheckSettingsInterface {

  /**
   * The parent check.
   *
   * @var \Drupal\security_review\Check
   */
  protected $check;

  /**
   * The configuration storage of the parent Check.
   *
   * @var \Drupal\Core\Config\Config $config
   */
  protected $config;

  /**
   * Creates a CheckSettings instance.
   *
   * @param \Drupal\security_review\Check $check
   *   The parent Check.
   * @param \Drupal\Core\Config\Config $config
   *   The parent Check's configuration.
   */
  public function __construct(Check $check, Config &$config) {
    $this->check = $check;
    $this->config = $config;
  }

  /**
   * {@inheritdoc}
   */
  public function get($key, $default_value = NULL) {
    $value = $this->config
      ->get('settings.' . $key);
    if ($value == NULL) {
      return $default_value;
    }
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    $this->config
      ->set('settings.' . $key, $value);
    $this->config
      ->save();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, array $values) {

    // Validation is optional.
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array $values) {

    // Handle submission.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CheckSettings::$check protected property The parent check.
CheckSettings::$config protected property The configuration storage of the parent Check.
CheckSettings::buildForm public function Form constructor. Overrides CheckSettingsInterface::buildForm 1
CheckSettings::get public function Gets a check-specific setting value identified by $key. Overrides CheckSettingsInterface::get
CheckSettings::set public function Sets a check-specific setting value identified by $key. Overrides CheckSettingsInterface::set
CheckSettings::submitForm public function Form submission handler. Overrides CheckSettingsInterface::submitForm 1
CheckSettings::validateForm public function Form validation handler. Overrides CheckSettingsInterface::validateForm
CheckSettings::__construct public function Creates a CheckSettings instance.