It would be great if you could add drag&drop-functionality to the created rules, so site builders could change the order of them being processed (and by that changing the output-order of messages to the user).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jfrederick’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
9.43 KB

See attached patch.

This patch adds a weight to validation rules. It replaces the validation rules admin interface with a form and a corresponding theme function, which formats the form as a drag and drop table.

When the validators are run, they are run in the order of their weight, as set in the drag and drop table. If you do not re-order the validators, their default weights are 0. If validation weights are equal, they are run in the order of ruleid DESC, just as they were in the past.

My main use case for this is to have conditional validation. I have one validator that I want to only run if all other validation has passed. Now, by placing this validator last, and checking form_get_errors(), I should be able to do this. Relates to How to create a conditional/dependent validator which is only triggered when all others validate

Disclaimer: The patch includes a schema update that adds a 'weight' field to the webform_validation_rule table. To run the schema update, run update.php or drush updb. Naturally, this update hook (7002) may interfere with the sequence of update hooks that may be introduced in the module henceforth. I still felt it best to move forward with more regular update hook numbering.

Please help fix up any mistakes in the patch, thanks!!

Liam Morland’s picture

Thanks for the patch. I will review it when I have time. If others can give it a try, that would be appreciated.

Liam Morland’s picture

Status: Needs review » Needs work

Thanks very much for the patch. I think this is a good feature to have. A few comments:

  • Please roll the patch from the webform_validation directory. The patch is rolled from sites, which means that if I clone webform_validation and enter that directory, the patch cannot be directly applied with git apply.
  • The new column needs to be added to webform_validation_schema() as well as the update hook. Otherwise, new installs will not get the new column.
  • The new column should be NOT NULL: everything has a weight and it could be zero.
  • The patch would be much easier to follow if it were split in two: One patch to redesign the admin interface with theme functions and the other to add the feature. It would be best to make a separate issue for the admin interface redesign. Then this issue can be for just adding the new feature.
  • Check your indentation in webform_validation_manage_overview_form_submit(). In the call to db_update(), the continuation lines, first one starting with "->fields", need to be indented.

Thanks again.

jfrederick’s picture

Status: Needs work » Needs review
FileSize
9.72 KB

Thanks for the suggestions, they were extremely helpful.

Attached is an updated patch. It fixes 4 out of 5 of the issues you raised, simply excluding the separation of the patch into two separate patches. The reason that is problematic is the conversion of the admin interface to a theme function is heavily tied to displaying the admin interface as a form. But without the new weight field, there is no reason to have the admin interface be a form; there would be nothing to submit.

But let me know what you think.

jfrederick’s picture

Heh, I included a stray dpm() in that patch. Removed in attachment.

Liam Morland’s picture

Liam Morland’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)
Liam Morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Patch (to be ported) » Closed (fixed)

Drupal 6 is no longer supported.