You are here

public function SensorManager::disableSensor in Monitoring 8

Same name and namespace in other branches
  1. 7 lib/Drupal/monitoring/Sensor/SensorManager.php \Drupal\monitoring\Sensor\SensorManager::disableSensor()

Disable a sensor.

Checks if the sensor is enabled and if so it will disable it and remove from the active sensor list.

Parameters

string $sensor_name: Sensor name to be disabled.

Throws

\Drupal\monitoring\Sensor\NonExistingSensorException Thrown if the requested sensor does not exist.

File

src/Sensor/SensorManager.php, line 225
Contains \Drupal\monitoring\Sensor\SensorManager.

Class

SensorManager
Manages sensor definitions and settings.

Namespace

Drupal\monitoring\Sensor

Code

public function disableSensor($sensor_name) {
  $sensor_config = $this
    ->getSensorConfigByName($sensor_name);
  if ($sensor_config
    ->isEnabled()) {
    $sensor_config->status = FALSE;
    $sensor_config
      ->save();
    $available_sensors = \Drupal::state()
      ->get('monitoring.available_sensors', array());
    $available_sensors[$sensor_name]['enabled'] = FALSE;
    $available_sensors[$sensor_name]['name'] = $sensor_name;
    \Drupal::state()
      ->set('monitoring.available_sensors', $available_sensors);
  }
}