You are here

protected function SensorForm::thresholdsForm in Monitoring 8

Builds the threshold settings form.

1 call to SensorForm::thresholdsForm()
SensorForm::form in src/Form/SensorForm.php
Gets the actual form array to be built.

File

src/Form/SensorForm.php, line 307
Contains \Drupal\monitoring\Form\SensorForm.

Class

SensorForm
Sensor settings form controller.

Namespace

Drupal\monitoring\Form

Code

protected function thresholdsForm(array &$form, FormStateInterface $form_state) {
  $type = $form_state
    ->getValue(array(
    'thresholds',
    'type',
  ));
  if (empty($type)) {
    $type = $this->entity
      ->getThresholdsType();
  }
  $form['plugin_container']['thresholds']['type'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Threshold type'),
    '#options' => array(
      'none' => $this
        ->t('- None -'),
      'exceeds' => $this
        ->t('Exceeds'),
      'falls' => $this
        ->t('Falls'),
      'inner_interval' => $this
        ->t('Inner interval'),
      'outer_interval' => $this
        ->t('Outer interval'),
    ),
    '#default_value' => $type,
    '#ajax' => array(
      'callback' => '::ajaxReplaceThresholdsForm',
      'wrapper' => 'monitoring-sensor-thresholds',
    ),
  );
  switch ($type) {
    case 'exceeds':
      $form['plugin_container']['thresholds']['type']['#description'] = $this
        ->t('The sensor will be set to the corresponding status if the value exceeds the limits.');
      $form['plugin_container']['thresholds']['warning'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning'),
      );
      $form['plugin_container']['thresholds']['critical'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical'),
      );
      break;
    case 'falls':
      $form['plugin_container']['thresholds']['type']['#description'] = $this
        ->t('The sensor will be set to the corresponding status if the value falls below the limits.');
      $form['plugin_container']['thresholds']['warning'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning'),
      );
      $form['plugin_container']['thresholds']['critical'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical'),
      );
      break;
    case 'inner_interval':
      $form['plugin_container']['thresholds']['type']['#description'] = $this
        ->t('The sensor will be set to the corresponding status if the value is within the limits.');
      $form['plugin_container']['thresholds']['warning_low'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning low'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning_low'),
      );
      $form['plugin_container']['thresholds']['warning_high'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning high'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning_high'),
      );
      $form['plugin_container']['thresholds']['critical_low'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical low'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical_low'),
      );
      $form['plugin_container']['thresholds']['critical_high'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical high'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical_high'),
      );
      break;
    case 'outer_interval':
      $form['plugin_container']['thresholds']['type']['#description'] = $this
        ->t('The sensor will be set to the corresponding status if the value is outside of the limits.');
      $form['plugin_container']['thresholds']['warning_low'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning low'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning_low'),
      );
      $form['plugin_container']['thresholds']['warning_high'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Warning high'),
        '#default_value' => $this->entity
          ->getThresholdValue('warning_high'),
      );
      $form['plugin_container']['thresholds']['critical_low'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical low'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical_low'),
      );
      $form['plugin_container']['thresholds']['critical_high'] = array(
        '#type' => 'number',
        '#title' => $this
          ->t('Critical high'),
        '#default_value' => $this->entity
          ->getThresholdValue('critical_high'),
      );
      break;
  }
  return $form;
}