At present, the "node" support for Better formats does not cover the modified body field used by webforms.

I've used a custom hook_form_alter to deal with this (see below), but it would be great if Better formats could support this widely-used module by default.

The following is simply a copy of better_formats_form_alter() and better_formats_set_node_format(), but looking for the webform format selector instead. It seems to work from an initial test. It doesn't deal with the per-node-type option, as I wasn't using that.

/**
 * Implementation of hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  // Add Webform support for Better formats module
  // @see better_formats_form_alter()
  if ($form['#id'] == 'node-form' && $form['type']['#value'] == 'webform') {
    mymodule_better_formats_set_webform_format($form);
  }
}

/**
 * Processes formats for webform body fields.
 *
 * @see mymodule_form_alter()
 */
function mymodule_better_formats_set_webform_format(&$form) {
  // Set webform body field.
  if (isset($form['webform']['settings']['format'])) {
    // Get default for new entries.
    $default = better_formats_get_default_format('node', $form['type']['#value']);

    if (empty($form['nid']['#value'])) {
      // Set format to default for new entries.
      $format = $default;
    }
    else {
      // Get existing format for core body field.
      $format = better_formats_get_current_format($form['webform']['settings']['format']);
    }

    // Overwrite the filter form with our own.
    $form['webform']['settings']['format'] = better_formats_filter_form($format, $default, 'node', $form['type']['#value']);
  }
}

Comments

dragonwize’s picture

Status: Active » Postponed (maintainer needs more info)

I agree webform support would be nice.

However, I added support for webform(2.7) and the issue is that the format is only applied to the "Confirmation message or redirect URL:" field instead of the "Description:" body field. That is because they have both fields but the format is not placed with the field so it uses that last field it is near.

I will have to look into the webform code and probably submit a patch to fix the way in which it is using formats.

As it stands, placing filtering on the confirmation area can be dangerous because it uses filters to check for URLs and messages in a certain format.

jweowu’s picture

Thanks for looking.

That combined "Confirmation message or redirect URL" field in webform is a really horrible design decision :/

I wish they'd split it into separate fields. Maybe I should log that request with them.

jweowu’s picture

FYI: #520524: Redirect URL and confirmation message should be two different fields

If that gets closed off, this could probably be re-visited.

dragonwize’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

6.x is now unsupported.