function _coder_settings_form in Coder 5.2
Same name and namespace in other branches
- 5 coder.module \_coder_settings_form()
- 6.2 coder.module \_coder_settings_form()
- 6 coder.module \_coder_settings_form()
Build settings form API array for coder.
Generates a form with the default reviews and default modules/themes to run Coder on.
@note Actual forms may have additional sections added to them, this is simply a base.
Parameters
$settings: Settings array for coder in the format of _coder_get_default_settings().
$system: Array of module and theme information, in form string theme/module name => boolean TRUE if checked by coder already.
$files: Associative array of files, in form string theme/module name => string filename to check.
Return value
Array for form API for the settings box.
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 - Implementation of hook_form().
File
- ./
coder.module, line 191 - 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] = isset($review['#link']) ? l($review['#title'], $review['#link']) : $review['#title'];
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,
);
// NOTE: Should rename var.
$form['coder_what']['coder_active_modules'] = array(
'#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 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,
'checkboxes' => array(
'#theme' => 'cols',
'#cols' => 2,
),
);
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,
'checkboxes' => array(
'#theme' => 'coder_checkboxes',
),
);
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"]['checkboxes']["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;
}