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've created a module that renders a "step bar" above the webform - for multipage weforms. The problem is that there it is currently impossible to add elements above the usual webform elements. This is due to the default webform-form.tpl.php hardcoding that order:
// Print out the main part of the form.
// Feel free to break this up and move the pieces within the array.
print drupal_render($form['submitted']);
// Always print out the entire $form. This renders the remaining pieces of the
// form that haven't yet been rendered above.
print drupal_render_children($form);
I think this should be done via weights or some other overrideable method.
Comments
Comment #1
quicksketchI'd suggest just upgrading to Webform 4.x, this functionality is built-into the module now. Though you're right that modifying the template was a requirement for the progress bar. The template now looks like this:
This shortcoming in flexibility is an intentional decision to make theming easier. Considering the functionality you're after is now built into the module anyway, are there any problems remaining? I'm going to mark this works as designed, please move back to "active" if you have any further questions.
Comment #2
torotil CreditAttribution: torotil commentedYes, I've heard about the progressbar in 7.x-4.x -- but since there is no stable version yet and we have several production sites - simply upgrading to a dev-version is not an option. I think I'll provide a patch for 7.x-3.x at some point.
Comment #3
torotil CreditAttribution: torotil commentedReading your code snippet from 7.x-4.x shows exactly the same as in 7.x-3.x. Now not only is the position of the form-elements hardcoded above anything else but also the progress bar. In my issue description the "step bar" was just an example. Every other module that wants to put some additional elements in the form will have the very same problem. Hardcoding elements in that way makes it impossible to override in either hook_form_alter() or theme-preprocess functions.
Comment #4
quicksketchYep it does, but that's the way it's intended to work. It's a balance between ease of theming and ease of module extension. Some modules include similar approaches, like comment.tpl.php or node.tpl.php. What you're asking for is essentially that there is no theming at all and then entire thing is just a renderable. If that's required on your sites, perhaps you could form_alter the form and remove #theme from the form. I don't anticipate removing the theming from forms to make them more easily modifiable to modules.
Comment #5
torotil CreditAttribution: torotil commentedThe default webform-form.tpl.php simply orders the elements. IMHO That's what $element[#weight] is intended for.
Comment #6
quicksketchThat is what weight is for, but in this case Webform is providing a template for demonstration purposes. In 4.x, it's not just ordering that's being used. Unless we switch to #theme_wrappers or a separate theme function for the preview message, we've now got markup that is in the template. Again it's good for demonstration.
For your Webform 3.x module, you can either A) put the progress bar inside of $form['submitted'] (I don't think this causes problems) or B) put a #theme_wrapper on the entire Webform form itself, which will allow you to place things above the entire form if you need.
Comment #7
torotil CreditAttribution: torotil commentedIt's also possible to don't actually use demonstration-only templates (as is done for fields I think).
But alright. I give up and put a pointer to this issue on the project page. Reasonable default behavior doesn't seem possible at this stage.