You are here

public function SensorEnabledModules::settingsForm in Monitoring 7

Gets settings form for a specific sensor.

Parameters

$form: Drupal $form structure.

array $form_state: Drupal $form_state object. Carrying the string sensor_name.

Return value

array Drupal form structure.

Overrides SensorConfigurable::settingsForm

File

lib/Drupal/monitoring/Sensor/Sensors/SensorEnabledModules.php, line 21
Contains \Drupal\monitoring\Sensor\Sensors\SensorEnabledModules.

Class

SensorEnabledModules
Monitors installed modules.

Namespace

Drupal\monitoring\Sensor\Sensors

Code

public function settingsForm($form, &$form_state) {
  $form = parent::settingsForm($form, $form_state);
  module_load_include('inc', 'system', 'system.admin');
  $form['allow_additional'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow additional modules to be enabled'),
    '#description' => t('If checked the additional modules being enabled will not be considered as an error state.'),
    '#default_value' => $this->info
      ->getSetting('allow_additional'),
  );

  // Get current list of modules.
  $modules = system_rebuild_module_data();
  $visible_modules = array();
  $hidden_modules = array();
  foreach ($modules as $module => $module_data) {

    // Skip profiles.
    if (strpos(drupal_get_path('module', $module), 'profiles') === 0) {
      continue;
    }

    // As we also include hidden modules, some might have no name at all,
    // make sure it is set.
    if (!isset($module_data->info['name'])) {
      $module_data->info['name'] = '- No name -';
    }
    if (!empty($module_data->info['hidden'])) {
      $module_data->info['name'] .= ' [' . t('Hidden module') . ']';
      $hidden_modules[$module] = $module_data;
    }
    else {
      $visible_modules[$module] = $module_data;
    }
  }
  uasort($visible_modules, 'system_sort_modules_by_info_name');
  uasort($hidden_modules, 'system_sort_modules_by_info_name');
  $default_value = $this->info
    ->getSetting('modules');
  if (empty($default_value)) {
    $default_value = module_list();
  }
  $options = array();
  foreach (array_merge($visible_modules, $hidden_modules) as $module => $module_data) {
    $options[$module] = $module_data->info['name'] . ' (' . $module . ')';
  }
  $form['modules'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#title' => t('Modules expected to be enabled'),
    '#description' => t('Check all modules that are supposed to be enabled.'),
    '#default_value' => $default_value,
  );
  return $form;
}