You are here

public function DatabaseAggregatorSensorPlugin::submitConfigurationForm in Monitoring 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides DatabaseAggregatorSensorPluginBase::submitConfigurationForm

File

src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php, line 594
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin.

Class

DatabaseAggregatorSensorPlugin
Database aggregator able to query a single db table.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);
  $settings = $this->sensorConfig
    ->getSettings();

  // Cleanup conditions, remove empty.
  $settings['conditions'] = [];
  foreach ($form_state
    ->getValue('conditions', []) as $key => $condition) {
    if (!empty($condition['field'])) {
      $settings['conditions'][] = $condition;
    }
  }

  // Update the verbose output fields.
  $settings['verbose_fields'] = [];
  foreach ($form_state
    ->getValue('verbose_fields', []) as $field) {
    if (!empty($field['field_key'])) {
      $settings['verbose_fields'][] = $field['field_key'];
    }
  }

  // Update the history status.
  if ($form_state
    ->getValue('settings')['aggregation']['time_interval_field']) {
    $settings['history_status'] = $form_state
      ->getValue('settings')['aggregation']['history_status'];
  }
  else {
    $settings['history_status'] = FALSE;
  }
  $this->sensorConfig
    ->set('settings', $settings);
}