You are here

function _coder_settings_form in Coder 5

Same name and namespace in other branches
  1. 5.2 coder.module \_coder_settings_form()
  2. 6.2 coder.module \_coder_settings_form()
  3. 6 coder.module \_coder_settings_form()
2 calls to _coder_settings_form()
coder_admin_settings in ./coder.module
Implementation of settings page for Drupal 5
coder_page_form in ./coder.module

File

./coder.module, line 157
Developer Module that assists with code review and version upgrade that supports a plug-in extensible hook system so contributed modules can define additional review standards.

Code

function _coder_settings_form($settings, &$system, &$files) {

  // add the javascript
  $path = drupal_get_path('module', 'coder');
  drupal_add_js($path . '/coder.js');

  // create the list of review options from the coder review plug-ins
  // maintain a secondary list based on #title only, to make sorting possible
  $reviews = _coder_reviews();
  foreach ($reviews as $name => $review) {
    $review_options[$name] = l($review['#title'], $review['#link']);
    if (isset($review['#description'])) {
      $review_options[$name] .= ' (' . $review['#description'] . ')';
    }
    $review_sort[$name] = $review['#title'];
  }

  // sort the reviews by #title
  asort($review_sort);
  foreach ($review_sort as $name => $review) {
    $review_sort[$name] = $review_options[$name];
  }

  // what reviews should be used?
  $form['coder_reviews_group'] = array(
    '#type' => 'fieldset',
    '#title' => t('Reviews'),
    '#collapsible' => true,
    '#collapsed' => false,
  );
  $form['coder_reviews_group']['coder_reviews'] = array(
    '#type' => 'checkboxes',
    '#options' => $review_sort,
    '#description' => t('apply the checked coding reviews'),
    '#default_value' => $settings['coder_reviews'],
  );

  // what severities should be used?
  $form['coder_reviews_group']['coder_severity'] = array(
    '#type' => 'radios',
    '#options' => array(
      1 => 'minor (most)',
      5 => 'normal',
      9 => 'critical (fewest)',
    ),
    '#description' => t('show warnings at or above the severity warning level'),
    '#default_value' => $settings['coder_severity'],
  );

  // get the modules and theme
  $sql = 'SELECT name, filename, type, status FROM {system} WHERE type=\'module\' OR type=\'theme\' ORDER BY weight ASC, filename ASC';
  $result = db_query($sql);
  $system_modules = array();
  $system_themes = array();
  while ($system = db_fetch_object($result)) {
    $display_name = $system->name;
    if ($system->status) {
      $display_name .= t(' (active)');
      $system_active[$system->name] = $system->name;
    }
    if (_coder_is_drupal_core($system)) {
      $display_name .= t(' (core)');
      $system_core[$system->name] = $system->name;
    }
    if ($system->type == 'module') {
      $system_modules[$system->name] = $system->name;
    }
    else {
      $system_themes[$system->name] = $system->name;
    }
    $system_links[$system->name] = l($display_name, "coder/{$system->name}");
    $files[$system->name] = $system->filename;
  }
  asort($system_links);

  // display what to review options
  $form['coder_what'] = array(
    '#type' => 'fieldset',
    '#title' => t('What to review'),
    '#collapsible' => true,
    '#collapsed' => false,
  );
  $form['coder_what']['coder_active_modules'] = array(
    // NOTE: should rename var
    '#type' => 'checkbox',
    '#default_value' => isset($settings['coder_active_modules']) ? $settings['coder_active_modules'] : 0,
    '#title' => t('active modules and themes'),
  );
  $form['coder_what']['coder_core'] = array(
    '#type' => 'checkbox',
    '#default_value' => isset($settings['coder_core']) ? $settings['coder_core'] : 0,
    '#title' => t('core files (php, modules, and includes)'),
  );
  $form['coder_what']['coder_includes'] = array(
    '#type' => 'checkbox',
    '#default_value' => $settings['coder_includes'],
    '#title' => t('include files (.inc and .php files)'),
  );
  if (arg(0) == 'admin') {
    $form['coder_what']['coder_cache'] = array(
      '#type' => 'checkbox',
      '#default_value' => $settings['coder_cache'],
      '#title' => t('use the experimental coder cache'),
    );
  }

  // display the modules in a fieldset
  $form['coder_what']['coder_modules'] = array(
    '#type' => 'fieldset',
    '#title' => t('Select Specific Modules'),
    '#collapsible' => true,
    '#collapsed' => true,
  );
  if (isset($settings['coder_all'])) {
    $modules = $system_modules;
  }
  elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
    if (isset($settings['coder_core']) && $settings['coder_core']) {
      $modules = array_intersect($system_active, $system_core);
      $modules = array_intersect($modules, $system_modules);
    }
    else {
      $modules = array_intersect($system_active, $system_modules);
    }
  }
  elseif (isset($settings['coder_core']) && $settings['coder_core']) {
    $modules = array_intersect($system_core, $system_modules);
  }
  elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
    $modules = array_intersect($system_active, $system_modules);
  }
  else {
    $modules = isset($settings['coder_modules']) && is_array($settings['coder_modules']) ? $settings['coder_modules'] : array();
  }

  // display the themes in a fieldset
  $form['coder_what']['coder_themes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Select Specific Themes'),
    '#collapsible' => true,
    '#collapsed' => true,
  );
  if (isset($settings['coder_all'])) {
    $themes = $system_themes;
  }
  elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
    if (isset($settings['coder_core']) && $settings['coder_core']) {
      $themes = array_intersect($system_active, $system_core);
      $themes = array_intersect($themes, $system_themes);
    }
    else {
      $themes = array_intersect($system_active, $system_themes);
    }
  }
  elseif (isset($settings['coder_core']) && $settings['coder_core']) {
    $themes = array_intersect($system_core, $system_themes);
  }
  elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
    $themes = array_intersect($system_active, $system_themes);
  }
  else {
    $themes = isset($settings['coder_themes']) && is_array($settings['coder_themes']) ? $settings['coder_themes'] : array();
  }
  foreach ($system_links as $name => $link) {
    $classes = array();
    if (in_array($name, $system_active)) {
      $classes[] = 'coder-active';
    }
    if (in_array($name, $system_core)) {
      $classes[] = 'coder-core';
    }
    if (in_array($name, $system_themes)) {
      $type = 'theme';
      $default_value = isset($themes[$name]);
    }
    else {
      $type = 'module';
      $default_value = isset($modules[$name]);
    }
    $form['coder_what']["coder_{$type}s"]["coder_{$type}s-{$name}"] = array(
      '#type' => 'checkbox',
      '#title' => $link,
      '#default_value' => $default_value,
      '#attributes' => array(
        'class' => implode(' ', $classes),
      ),
    );
  }
  $system = array_merge($modules, $themes);
  return $form;
}