0

I would like to include the description field when viewing individual webform submissions for each component. The standard webform individual submission display shows the label and the answer, but the description field for the component is not shown.

I had a look at webform-submission.tpl.php but wasn't sure how I could modify this to include the description being displayed.

Can anyone tell me how I can get the description to display?

I'm using Drupal 7 with Webform 7.x-4.19

0

After looking through the webform module I found out how to achieve this.

I used hook_webform_component_display_alter() which is there to enable customising the display of components in display only contexts. This function is in webform.api.php. I created my own function using this hook in a custom module to add the description to all textfield components as follows:

<?php
function my_mod_webform_component_display_alter(array &$element, array &$component) {
  if ($component['type'] == 'textfield') {
    $element['#description'] = $component['extra']['description'];
  }
}

For reference, the notes and example given from the webform module for hook_webform_component_display_alter() are:

/**
 * Allow modules to modify a "display only" webform component.
 *
 * @param array $element
 *   The display element as returned by _webform_display_component().
 * @param array $component
 *   A Webform component array.
 *
 * @see _webform_display_component()
 */
function hook_webform_component_display_alter(array &$element, array &$component) {
  if ($component['cid'] == 10) {
    $element['#title'] = 'My custom title';
    $element['#default_value'] = 42;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.