You are here

public function ContentEntityAggregatorSensorPlugin::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/ContentEntityAggregatorSensorPlugin.php, line 501
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin.

Class

ContentEntityAggregatorSensorPlugin
Content entity database aggregator.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);

  /** @var \Drupal\monitoring\Form\SensorForm $sensor_form */
  $sensor_form = $form_state
    ->getFormObject();

  /** @var \Drupal\monitoring\SensorConfigInterface $sensor_config */
  $sensor_config = $sensor_form
    ->getEntity();
  $settings = $sensor_config
    ->getSettings();

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