You are here

protected function IgnoredModulesForm::buildTable in Nagios Monitoring 8

Build the list of modules

Parameters

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

boolean $enabled: Enable the check boxes

1 call to IgnoredModulesForm::buildTable()
IgnoredModulesForm::buildForm in src/Form/IgnoredModulesForm.php
Form constructor.

File

src/Form/IgnoredModulesForm.php, line 123

Class

IgnoredModulesForm

Namespace

Drupal\nagios\Form

Code

protected function buildTable(array &$form, $enabled) {
  $config = $this
    ->config('nagios.settings');
  $header = [
    'title' => $this
      ->t('Title'),
    'description' => $this
      ->t('Description'),
  ];
  $options = [];

  // Include system.admin.inc so we can use the sort callbacks.
  $this->moduleHandler
    ->loadInclude('system', 'inc', 'system.admin');

  // Sort all modules by their names.
  $modules = \Drupal::service('extension.list.module')
    ->getList();
  uasort($modules, 'system_sort_modules_by_info_name');

  // Build the rows
  foreach ($modules as $filename => $module) {
    if (empty($module->info['hidden'])) {
      $options[$filename] = $this
        ->buildRow($module);
      $options[$filename]['#disabled'] = TRUE;
    }
  }

  // Set up the check boxes
  $defaults = [];
  $nagios_ignored_modules = $config
    ->get('nagios.ignored_modules') ?: [];
  foreach ($nagios_ignored_modules as $ignored_module) {
    $defaults[$ignored_module] = 1;
  }
  $form['modules'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => $this
      ->t('No modules available.'),
    '#default_value' => $defaults,
  ];
  if (!$enabled) {
    foreach ($form['modules']['#options'] as $key => $value) {
      $form['modules']['#options']['#disabled'] = TRUE;
    }
  }
}