function coder_page_form in Coder 6
Same name and namespace in other branches
- 5.2 coder.module \coder_page_form()
- 5 coder.module \coder_page_form()
- 6.2 coder.module \coder_page_form()
Implementation of hook_form().
Implements coder's main form, in which a user can select reviews and modules/themes to run them on.
1 call to coder_page_form()
1 string reference to 'coder_page_form'
- coder_page in ./
coder.module - Implementation of code review page.
File
- ./
coder.module, line 660 - 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_page_form($form_state) {
if (isset($form_state['storage'])) {
$settings = $form_state['storage'];
$settings['coder_modules'] = _coder_settings_array($form_state, 'module');
$settings['coder_themes'] = _coder_settings_array($form_state, 'theme');
drupal_set_title(t('Code review (submitted options)'));
}
else {
$arg = arg(1);
$settings = _coder_get_default_settings($arg);
if ($arg) {
drupal_set_title(t('Code review (@options)', array(
'@options' => isset($arg) ? $arg : 'default options',
)));
}
}
// Get this once: list of the reviews to perform.
$reviews = array();
$avail_reviews = _coder_reviews();
$selected_reviews = $settings['coder_reviews'];
foreach ($selected_reviews as $name => $checked) {
if ($checked) {
$reviews[$name] = $avail_reviews[$name];
}
}
if ($coder_form = _coder_settings_form($settings, $system, $files)) {
// Add style sheet.
$path = drupal_get_path('module', 'coder');
drupal_add_css($path . '/coder.css', 'module');
// Get the includes_exclusions settings once, it is used multiple times.
$coder_includes_exclusions = isset($settings['coder_includes_exclusions']) ? $settings['coder_includes_exclusions'] : '';
// Code review non-module core files.
$module_weight = 0;
if (isset($settings['coder_core']) && $settings['coder_core']) {
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
);
$form['core_php'] = array(
'#type' => 'fieldset',
'#title' => 'core (php)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
$phpfiles = file_scan_directory('.', '.*\\.php', array(
'.',
'..',
'CVS',
), 0, FALSE, 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_php', $phpfiles, 2, 0, $coder_includes_exclusions);
$form['core_includes'] = array(
'#type' => 'fieldset',
'#title' => 'core (includes)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
$includefiles = drupal_system_listing('.*\\.inc$', 'includes', 'filename', 0);
_coder_page_form_includes($form, $coder_args, 'core_includes', $includefiles, 0, $coder_includes_exclusions);
}
// Loop through the selected modules and themes.
if (isset($system)) {
// Used to avoid duplicate includes.
$dups = array();
$stats = array();
$patch = '';
foreach ($system as $name => $checked) {
if ($checked) {
// Process this one file.
$filename = $files[$name];
if (!$filename) {
drupal_set_message(t('Code Review file for %module not found', array(
'%module' => $name,
)));
continue;
}
if (!empty($settings['coder_patches'])) {
$patch = $filename;
$filename = $name;
}
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#filename' => $filename,
'#patch' => $patch,
);
$results = do_coder_reviews($coder_args);
$stats[$filename] = $results['#stats'];
unset($results['#stats']);
// Output the results in a collapsible fieldset.
$form[$name] = array(
'#type' => 'fieldset',
'#title' => $filename,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
if (empty($results)) {
$results[] = t('No Problems Found');
}
else {
$form[$name]['#collapsed'] = FALSE;
}
$form[$name]['output'] = array(
'#value' => theme('coder', $name, $filename, $results),
'#weight' => -1,
);
// Process the same directory include files.
if (!empty($settings['coder_includes'])) {
// NOTE: Convert to the realpath here so drupal_system_listing
// doesn't return additional paths (i.e., try "module").
if ($path = str_replace('\\', '/', dirname(realpath($filename)))) {
if (!isset($dups[$path])) {
if (substr($filename, -7) == '.module') {
$coder_args['#php_minor'] = 1;
}
$dups[$path] = 1;
$includefiles = drupal_system_listing('.*\\.(inc|php|js|install|test)$', dirname($filename), 'filename', 0);
$offset = strpos($filename, dirname($filename));
$stats[$filename]['#includes'] = _coder_page_form_includes($form, $coder_args, $name, $includefiles, $offset, $coder_includes_exclusions);
}
}
}
}
}
if (count($stats)) {
$summary = array(
'files' => 0,
'minor' => 0,
'normal' => 0,
'critical' => 0,
);
foreach ($stats as $stat) {
if (isset($stat['#includes'])) {
foreach ($stat['#includes'] as $includestat) {
$summary['files']++;
$summary['minor'] += $includestat['minor'];
$summary['normal'] += $includestat['normal'];
$summary['critical'] += $includestat['critical'];
}
}
$summary['files']++;
}
$display = array();
if (empty($settings['coder_patches'])) {
$display[] = t('Coder found @count projects', array(
'@count' => count($stats),
));
$display[] = t('@count files', array(
'@count' => $summary['files'],
));
}
else {
$display[] = t('Coder found @count patches', array(
'@count' => count($stats),
));
}
foreach (array(
'critical',
'normal',
'minor',
) as $severity_name) {
if ($summary[$severity_name] > 0) {
$display[] = t('@count %severity_name warnings', array(
'@count' => $summary[$severity_name],
'%severity_name' => $severity_name,
));
}
}
drupal_set_message(implode(', ', $display));
if (function_exists('_coder_drush_is_option') && _coder_drush_is_option('drush')) {
print coder_print_drush_messages();
}
}
}
// Prepend the settings form.
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Selection form'),
'#collapsible' => TRUE,
'#collapsed' => isset($form),
'#weight' => -1,
);
if ($form['settings']['#collapsed']) {
$form['settings']['#prefix'] = t('<div class="coder-settings">Use the Selection form to select options for this code review, or change the <a href="@settings">Default Settings</a> and use the <a href="@default">Default</a> tab above.</div>', array(
'@settings' => url('admin/settings/coder'),
'@default' => url('coder/default'),
));
}
$form['settings'][] = $coder_form;
$form['settings']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
return $form;
}