2

I am looking to have a webform posted to specific destination depending on submitted values.

I thought this could be done through the webform api, webform.api.php line 209 has this hook defined:

/**
 * Alter the display of a Webform submission.
 *
 * This function applies to both e-mails sent by Webform and normal display of
 * submissions when viewing through the adminsitrative interface.
 *
 * @param $renderable
 *   The Webform submission in a renderable array, similar to FormAPI's
 *   structure. This variable must be passed in by-reference. Important
 *   properties of this array include #node, #submission, #email, and #format,
 *   which can be used to find the context of the submission that is being
 *   rendered.
 */
function hook_webform_submission_render_alter(&$renderable) {
  // Remove page breaks from sent e-mails.
  if (isset($renderable['#email'])) {
    foreach (element_children($renderable) as $key) {
      if ($renderable[$key]['#component']['type'] == 'pagebreak') {
        unset($renderable[$key]);
      }
    }
  }
}

So I set out to use it with the following ina custom module:

// Implements hook_webform_submission_render_alter
function formHelper_webform_submission_render_alter(&$renderable) {
  // Just a dump to confirm hook was invoked...
  kpr($renderable);
  dpm($renderable);
}

However, it seems the hook is not being called. Am I missing something in here to use webform api? Is this even a regular hook? it seems I could get away with just calling the api's function but I would like to be sure of the Drupal way to go.

2
  • 1
    Although unrelated, FYI you shouldn't really use camel case with Drupal Coding Standards
    – Chapabu
    May 28, 2012 at 22:23
  • Thanks for pointing that out! I will rename the module form_helper. Although I have read the standards a couple of times, I missed the importance of the module's name to have lowercase hook functions. Lesson learned! Kudos to you friend May 29, 2012 at 4:24

1 Answer 1

1

Was not sure wether to delete original question or not, but decided on leaving it here since it is listed by google when searching for webform api help.

Turns out the code above does execute the hook. I went for lunch, came back, retried and suddenly the hook is invoked as expected.

To anyone needing to change form values or email info on submission of a webform, this hook is the real deal.

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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