You are here

function nagios_form_system_modules_alter in Nagios Monitoring 7

Implements hook_form_FORMID_alter().

Modify the module display view by adding a nagios ignore link to every module description.

File

./nagios.module, line 492

Code

function nagios_form_system_modules_alter(&$form) {
  if (isset($form['confirm']) || !user_access('administer nagios ignore')) {
    return;
  }

  // We need to abort if the Update module is not installed.
  if (!db_table_exists('cache_update')) {
    watchdog('nagios', t('The core update module was never installed so we cannot use update check features.'));
    return;
  }
  $nagios_ignored_modules = variable_get('nagios_ignored_modules', []);
  $projects_data = _nagios_update_get_projects();
  foreach ($form['modules'] as $package_name => &$package) {
    if ($package_name[0] != '#') {
      foreach ($package as $module_name => &$module) {
        if ($module_name[0] != '#') {
          if (array_key_exists($module_name, $projects_data) && !empty($module['enable']['#default_value'])) {
            $tooltip = [
              'title' => t('If checked, this module’s update status and hook_requirements() implementation is ignored.'),
            ];
            $module['links']['nagios_ignore'] = [
              '#type' => 'checkbox',
              '#title' => t('Ignore from Nagios'),
              '#default_value' => !empty($nagios_ignored_modules[$module_name]),
              '#attributes' => $tooltip,
            ];
            if (!module_exists('coder_review')) {
              $package['#theme'] = 'nagios_modules_fieldset';
            }
          }
        }
      }
      unset($module);
    }
  }
  unset($package);
  $form['#submit'][] = 'nagios_system_modules_form_submit';
}