Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a workflow with 3 different states (draft, review, publish). Now I want to limit validations for few fields when submitting with draft state. For that I have added $form['actions']['workflow_course_status_save_as_draft']['#limit_validation_errors'] = array();
still all the fields are getting validated.
I have checked without workflow and it is working fine. So from the looks of it, I think Workflow module is overriding these settings.
Comments
Comment #2
johnvI did a quickscan of the Workflow code. It is possible , if there is an error in function workflow_form_alter().
But only if you have set the 'state list' to 'action buttons', not to radio_buttons.
How is your configuration on /admin/config/workflow/workflow/MY_WORKFLOW/edit under 'How to show the available states' ?
If possible debug the code of function workflow_form_alter() in file workflow.form.inc
Comment #3
nicobot CreditAttribution: nicobot at Front ID commentedI have the same situation with Workflow 7.x-2.10; when I set #limit_validation_errors in a workflow button, it stops saving any transition.
Any idea why is this happening?
Comment #4
nicobot CreditAttribution: nicobot at Front ID commentedSo I figured this out. The reason why this is failing is that we're not using properly #limit_validation_errors. This issue has nothing to do with Workflow.
During the form validation, if this property is set (validation errors are limited), Drupal core will remove any non validated form values from the form state, so only values that passed validation will be left for submit callbacks.
For Drupal 8:
http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Form/FormVal...
For Drupal 7:
http://cgit.drupalcode.org/drupal/tree/includes/form.inc?h=7.x#n1193
My solution was to add a button validation that will be executed at end of all validations, and in there remove all form-related errors:
Comment #5
johnvOK, thanks for the heads-up. So what is the status now?
Should something be changed in the Workflow module, or is all OK?
I didn't know about '#limit_validation_errors', but maybe it should be implmented?
Comment #6
johnv