You are here

class SensorVariable in Monitoring 7

Monitors a variable value.

Hierarchy

Expanded class hierarchy of SensorVariable

See also

variable_get()

File

lib/Drupal/monitoring/Sensor/Sensors/SensorVariable.php, line 18
Drupal\monitoring\Sensor\Sensors\SensorVariable.

Namespace

Drupal\monitoring\Sensor\Sensors
View source
class SensorVariable extends SensorConfigurable {

  /**
   * {@inheritdoc}
   */
  public function settingsForm($form, &$form_state) {
    $form = parent::settingsForm($form, $form_state);
    if (is_array($this->info
      ->getSetting('variable_value'))) {
      return $form;
    }
    $form['variable_value'] = array(
      '#type' => 'textfield',
      '#title' => t('Expected value of variable %variable', array(
        '%variable' => $this->info
          ->getSetting('variable_name'),
      )),
      '#default_value' => $this->info
        ->getSetting('variable_value'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function runSensor(SensorResultInterface $result) {
    $result
      ->setValue(variable_get($this->info
      ->getSetting('variable_name'), $this->info
      ->getSetting('variable_default_value')));
    $result
      ->setExpectedValue($this->info
      ->getSetting('variable_value'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Sensor::$info protected property Current sensor info object.
Sensor::getSensorName public function Gets sensor name (not the label). Overrides SensorInterface::getSensorName
Sensor::isEnabled public function Determines if sensor is enabled. Overrides SensorInterface::isEnabled
Sensor::__construct function Instantiates a sensor object. 1
SensorConfigurable::settingsFormValidate public function Form validator for a sensor settings form. Overrides SensorConfigurableInterface::settingsFormValidate 1
SensorVariable::runSensor public function Runs the sensor, updating $sensor_result. Overrides SensorInterface::runSensor
SensorVariable::settingsForm public function Gets settings form for a specific sensor. Overrides SensorConfigurable::settingsForm