You are here

function theme_nagios_modules_fieldset in Nagios Monitoring 7

Returns HTML for the modules form.

This was copied from coder_review.admin.inc which was in turn copied from theme_system_modules_fieldset() and modified to handle additional links.

@todo Create an issue for this and get this function into D8.

Parameters

array $variables: An associative array containing the key:

  • form: A render element representing the form.

Return value

string

Throws

\Exception

File

./nagios.module, line 1230

Code

function theme_nagios_modules_fieldset($variables) {
  $form = $variables['form'];

  // Individual table headers.
  $rows = [];

  // Iterate through all of the modules to Determine the available operations.
  $children = element_children($form);
  $operations = drupal_map_assoc([
    'help',
    'permissions',
    'configure',
  ]);
  foreach ($children as $key) {
    $links = array_filter(array_keys($form[$key]['links']), function ($var) {
      return $var && $var[0] != '#';
    });
    if ($links) {
      $operations += drupal_map_assoc($links);
    }
  }

  // Iterate through all the modules.
  foreach ($children as $key) {

    // Stick it into $module for easier accessing.
    $module = $form[$key];
    $row = [];
    unset($module['enable']['#title']);
    $row[] = [
      'class' => [
        'checkbox',
      ],
      'data' => drupal_render($module['enable']),
    ];
    $label = '<label';
    if (isset($module['enable']['#id'])) {
      $label .= ' for="' . $module['enable']['#id'] . '"';
    }
    $row[] = $label . '><strong>' . drupal_render($module['name']) . '</strong></label>';
    $row[] = drupal_render($module['version']);

    // Add the description, along with any modules it requires.
    $description = drupal_render($module['description']);
    if ($module['#requires']) {
      $description .= '<div class="admin-requirements">' . t('Requires: !module-list', [
        '!module-list' => implode(', ', $module['#requires']),
      ]) . '</div>';
    }
    if ($module['#required_by']) {
      $description .= '<div class="admin-requirements">' . t('Required by: !module-list', [
        '!module-list' => implode(', ', $module['#required_by']),
      ]) . '</div>';
    }
    $row[] = [
      'data' => $description,
      'class' => [
        'description',
      ],
    ];

    // Display links (such as help or permissions) in their own columns.
    foreach ($operations as $key_inner) {
      $row[] = [
        'data' => drupal_render($module['links'][$key_inner]),
        'class' => [
          $key_inner,
        ],
      ];
    }
    $form['#header'][4]['colspan'] = count($operations);
    $rows[] = $row;
  }
  return theme('table', [
    'header' => $form['#header'],
    'rows' => $rows,
  ]);
}