You are here

public function SensorListBuilder::submitForm in Monitoring 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/SensorListBuilder.php, line 207
Contains \Drupal\monitoring\SensorListBuilder.

Class

SensorListBuilder
Defines a class to build a listing of sensor config entities.

Namespace

Drupal\monitoring

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue('sensors') as $sensor_id => $enabled) {

    /** @var \Drupal\monitoring\Entity\SensorConfig $sensor */
    $sensor = SensorConfig::load($sensor_id);
    if ($enabled) {
      $sensor->status = TRUE;
    }
    else {
      $sensor->status = FALSE;
    }
    $sensor
      ->save();
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('Configuration has been saved.'));
}