Description

Webform Calculation Components provides AJAX functionality to perform basic arithmetic operations on webform components. With this module the user can have calculated fields, e.g. the total amount, calculated percentage etc.
This module provides two new webform component types, Caluculation number and Calculation hidden.

Typical use cases are:

  • Inserting simple formulas in the webform.
  • Calculations in a spreadsheet fashion (I recommend that you create new Calculation number fields). E.g. the total amount is the sum of the column of amounts above.
  • Quotation forms to estimate prices without using the functionality of an ecommerce module. E.g. If the user checks a select option it adds the price of an element to the total price. (I recommend that you create new Calculation hidden fields).

The configuration of the components is like any other webform component. This project allows non-technical users to configure calculations using an easy user interface.
It has been tested to support webform-4.x .

Sandbox

https://drupal.org/sandbox/anthony_goode/2272403

There are screenshots with two examples and the corresponding settings.

Git

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/anthony_goode/2272403.git webform_calculation_components
cd webform_calculation_components

This project has been developed because I have often read requests to insert some kind of calculated fields (including my business partner). This question posted in Drupal answers illustrates it:

How can I create a custom calculator on a drupal site?

Manual reviews of other projects:

https://drupal.org/node/2275959#comment-8839801
https://drupal.org/node/2215985#comment-8866075
https://drupal.org/node/2299443#comment-8953337

Comments

Anthony Goode’s picture

Issue summary: View changes
Anthony Goode’s picture

Status: Active » Needs review
Anthony Goode’s picture

Issue tags: +PAreview: review bonus
Anthony Goode’s picture

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxanthony_goode2272403git

I'm a robot and this is an automated message from Project Applications Scraper.

Anthony Goode’s picture

About the parerview.sh errors on _webform_components functions, it says that those functions have to be renamed with the module's name. I found that every module that uses those webform API functions does not prefix the module name. E.g.:

uc_webform_component_hidden_product.inc

If those functions are renamed with the module's name, it shows an errors saying:

The webform component … is not able to be displayed.

Because those webform component functions are not called. They belong to the webform module. So those remaining errors reported by pareview.sh cannot be prevented.

The rest of the issues has been fixed.

Anthony Goode’s picture

Status: Needs work » Needs review
dragonmantank’s picture

Status: Needs review » Needs work

Your branch name should be changed from 'master' to something like '7.x-1.x' to follow proper dev guidelines.

In the js files and the .module file, I'd removed the commented out code for the console.log() calls. Commented out debug code shouldn't be released.

I'd removed the .install file since it is basically empty except for the comments.

Would it be possible to refactor webform_calculation_components_form_alter() to reduce the amount of code duplication? It seems like there is a lot of boilerplate between the number and calc types, which can lead to maintenance problems down the line.

Anthony Goode’s picture

Hi,

First of all, thank you for the review. I added the 7.x-1.x and removed the master branch. I also removed the console.log() calls and the .install file.

In regard to the refactoring of the webform_calculation_components_form_alter(), the boilerplate code is related with the inserting of the AJAX functionality to the corresponding webform field. It is done in the standard way according to the Form API. I think that other alternatives are more difficult to read and can be messy.

Cheers!

Anthony Goode’s picture

Status: Needs work » Needs review
Anthony Goode’s picture

Issue summary: View changes
Anthony Goode’s picture

Issue summary: View changes
Anthony Goode’s picture

Issue summary: View changes
Anthony Goode’s picture

Issue tags: +PAreview: review bonus
gbisht’s picture

Status: Needs review » Needs work

You have changed your branch from master to 7.x-1.x but your git clone path is still wrong and you have provided git path which is only for you because it will ask for password.
So please change it to:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/anthony_goode/2272403.git webform_calculation_components

mpdonadio’s picture

Issue summary: View changes
Status: Needs work » Needs review

The wrong git link isn't reason enough to warrant going back to **Needs Work**, especially if it is the only thing being reported (and anyone can edit the issue summaries to fix this). I changed the git link.

Were there any problems with the module or code itself? Setting back to **Needs Review**

klausi’s picture

Assigned: Unassigned » heddn
Status: Needs review » Reviewed & tested by the community
Issue tags: -PAreview: review bonus

Thanks your for your reviews. When finishing your review comment also set the issue status either to "needs work" (you found some problems with the project) or "reviewed & tested by the community" (you found no major flaws).

Review of the 7.x-1.x branch:

  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
    
    FILE: /home/klausi/pareview_temp/js/webform_calc_number_component.js
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | Missing file doc comment
    --------------------------------------------------------------------------------
    
    
    FILE: /home/klausi/pareview_temp/js/webform_calc_hidden_component.js
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | Missing file doc comment
    --------------------------------------------------------------------------------
    

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

manual review:

  1. https://www.drupal.org/project/webform_calculator - please describe the difference to the existing project on your project page.
  2. The Git commits are not connected to your user account. You need to specify an email address. See https://www.drupal.org/node/1022156 and https://www.drupal.org/node/1051722
  3. There are a couple of commented out dpm() calls in your code.
  4. "@to-do" should be just "@todo", see https://www.drupal.org/coding-standards/docs#todo
  5. I'm not that familiar with webform logic, but it seems you are applying the XSS sanitization functions in the right places.

Otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

Assigning to heddn as he might have time to take a final look at this.

Anthony Goode’s picture

Hi,

First of all, thank you for the reviews.

I have changed "@to-do" for "@todo" and removed the two commented out dpm calls.

Also I set my git user name to coincide with my drupal.org user account.

I have included the differences with the webform calculator module on the module page, although I have not been able to test it, because as it is said in its issues currently it does not work.

In regard of

“Coder Sniffer has found some issues with your code (please check the Drupal coding standards)
1 | ERROR | Missing file doc comment”

As you can check the @file tag is in both files. I have not found any combination for not getting an error (if I am wrong please let me know), and I noticed that I am not the only one. This recent issue of the Coder module is about that:

Coder_Review does not recognize @file docblock in .js files
https://www.drupal.org/node/1834598

Note: the Comment #10 of the issue suggests that we use commented opening php tags, but it also says that it throws a warning, and I do not think that using php tags in a Java script file is appropriate.

Cheers!

heddn’s picture

Status: Reviewed & tested by the community » Fixed

Automated review:

     webform_calc_number_component.js    Duplicate declaration at line 22, 26, 30, 34, 38, 42
     webform_calc_number_component.js    Variable result_field implicitly declared at line 21, 29, 32, 69
webform_calculation_components/components/wb_calc_number.inc  Variable 'decimals' might have not been defined (at line 272)
components/wb_calc_number.inc  Variable 'matches' might have not been defined (at line 272)

Manual review:

  • Don't concatenate into t(). Use string replacement arguments. Same applies in _webform_edit_wb_calc_number().
    function _webform_edit_wb_calc_hidden($component) {
      ...
        '#description' => t('The default value of the field.') . ' ' . theme('webform_token_help'),
  • Don't use html in t(); it makes translation more difficult. Instead use '%' replacement variables for emphasis.
    function _webform_edit_wb_calc_hidden($component) {
    ...
    $form['display']['calculation_hidden_type'] = array(
    
        '#description' => t('Both types of webform hidden calculation fields are not shown to end-users. Using a <em>Secure value</em> allows the use of <em>all tokens</em>, even for anonymous users.'),
  • Don't concatenate t() strings together. Just make a longer string. I see this in a couple places.
    function _webform_edit_wb_calc_number($component) {
        '#description' => t('Width of the webform calculation number field.') . ' ' . t('Leaving blank will use the default size.'),
        '#size' => 5,
        '#maxlength' => 10,
        '#weight' => 0,
        '#parents' => array('extra', 'width'),

None of these are blocking issues though, so...

Thanks for your contribution, Anthony!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

Anthony Goode’s picture

Hi @heddn,

Thank you for the review. I have promoted the sandbox project to a full project but I was mistaken and left the short name with the default number (I thought that the title of the module was enough). Now I can edit the project, but it shows an error every time I try to save it. The error says:
Short name must follow PHP naming convention.
because the short name is a number.

Is there any way of changing the short name from the number to: webform_calculation_components so I can update it?

https://www.drupal.org/project/2272403

Then I can correct the minor errors of the automatic and manual review.

Thanks in advance, cheers!

heddn’s picture

Unfortunately I can't fix that for you. Please open an issue to the d.o. infrastructure team. An issue with a similar problem to get a feel for the process: https://www.drupal.org/node/1421354

Anthony Goode’s picture

@heddn,

Thanks so much for your help and quick response. I opened the issue in the d.o. infrastructure team.

Project can not be updated because the short name is wrong (a number)

Cheers.

Anthony Goode’s picture

Hi,

The issue of the short name was fixed. Now it is a full project:

Webform Calculation Components

@heddn I also corrected the minor errors of the automatic and manual review.

Thanks to all the reviewers, I am grateful to you for all your help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.