Hi hurley, thanks for the work.
Here is the list of issues which needs to be ...

Contribution Date
Technology
Contribution Details

Hi hurley, thanks for the work.

Here is the list of issues which needs to be fixed.

1) Is there exists any special need to add js and css to "gpa_calculator_settings_form" via form_alter?
If not you can add the js and css in the form constructor function itself.

function gpa_calculator_form_alter(&$form, &$form_state, $form_id) { switch ($form_id) { case 'gpa_calculator_settings_form': drupal_add_css(drupal_get_path('module', 'gpa_calculator') . '/css/gpa_calculator.admin.css'); drupal_add_js(drupal_get_path('module', 'gpa_calculator') . '/js/gpa_calculator.admin.js', array('scope' => 'footer')); break; } }

2) Keep consistency when providing parameters to the form constructor functions. you have created two forms each with different signatures i;e

/** * GPA Calculator settings form. */ function gpa_calculator_settings_form() {

and

/** * GPA Calculator form. */ function gpa_calculator_form($form, &$form_state) {

3) You can use $form['#attached']['js']/$form['#attached']['css'] to add js/css to your form. It takes care of loading of js/css also when form is served form cache. Its a good practice to have.

4) There a various place where unnecessary variables have been used.
for eg

$gpa_calculator_school_name = variable_get('gpa_calculator_school_name', ''); $gpa_calculator_instructions = variable_get('gpa_calculator_instructions', ''); $gpa_calculator_grades = variable_get('gpa_calculator_grades', ''); $form['gpa_calculator'] = array( '#type' => 'fieldset', '#title' => t('Settings for GPA Calculator'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['gpa_calculator']['gpa_calculator_school_name'] = array( '#type' => 'textfield', '#title' => t('School'), '#description' => t('Enter you school\'s name here. If blank, block subject will read as "GPA Calculator."'), '#default_value' => $gpa_calculator_school_name, ); $form['gpa_calculator']['gpa_calculator_instructions'] = array( '#type' => 'textarea', '#title' => t('Instructions'), '#description' => t('Provide instructions or a description for your GPA calculator.'), '#default_value' => $gpa_calculator_instructions, ); $grades_options_example = ' 4.0|A '; $grades_options_example .= '3.67|A- '; $grades_options_example .= '3.33|B+ '; $grades_options_example .= '3.0|B '; $grades_options_example .= '2.67|C+ '; $grades_options_example .= '2.33|C '; $grades_options_example .= '2.0|C- '; $grades_options_example .= '1.67|D+ '; $grades_options_example .= '1.33|D '; $grades_options_example .= '1.0|D- '; $grades_options_example .= '0.0|F'; $grades_description = t('Enter grade options for the select box values. Key-value pairs must be entered separated by pipes. i.e. safe_key|Some readable option on separate lines. If blank, default values will be:') . $grades_options_example; $form['gpa_calculator']['gpa_calculator_grades'] = array( '#type' => 'textarea', '#title' => t('Grades'), '#description' => check_plain($grades_description), '#default_value' => $gpa_calculator_grades, ); $form = system_settings_form($form); return $form; $gpa_table_head = '<div id="grades_table">'; $gpa_table_head .= '<div class="gpa-table-thead">'; $gpa_table_head .= '<div class="gpa-table-cell gpa-th">#</div>'; $gpa_table_head .= '<div class="gpa-table-cell gpa-th">' . t('Class/Course Name') . '</div>'; $gpa_table_head .= '<div class="gpa-table-cell gpa-th">' . t('Grade') . '</div>'; $gpa_table_head .= '<div class="gpa-table-cell gpa-th">' . t('Credits Earned') . '</div>'; $gpa_table_head .= '</div>'; $gpa_table_head .= '<div class="gpa-table-body"></div>'; $form['gpa_table_head'] = array( '#markup' => $gpa_table_head, ); $gpa_table_end = '</div>'; $form['gpa_table_end'] = array( '#markup' => $gpa_table_end, ); module_load_include('inc', 'gpa_calculator', 'gpa_calculator'); $gpa_calculator_school_name = variable_get('gpa_calculator_school_name', '') . ' '; $gpa_calculator = drupal_get_form('gpa_calculator_form'); $blocks['subject'] = $gpa_calculator_school_name . t('GPA Calculator'); $blocks['content'] = $gpa_calculator;

There are few other examples also but i think you got the point

One example of correct usage may be

$form['gpa_calculator']['gpa_calculator_school_name'] = array( '#type' => 'textfield', '#title' => t('School'), '#description' => t('Enter you school\'s name here. If blank, block subject will read as "GPA Calculator."'), '#default_value' => variable_get('gpa_calculator_school_name', ''), );

Declaring variables should be minimized until and unless really needed since every variable takes some memory space.

5) Instead of using $(document).ready(function() {}) in your javascript file you should use

Drupal.behaviors.myModuleBehavior = function (context) { //Do some fancy stuff };

see drupal javascript api for more details

Contribution Author
Files count
0
Patches count
0