You are here

webform_optionsmarkup.module in Webform Options Markup 7.2

Same filename and directory in other branches
  1. 7 webform_optionsmarkup.module

Main module file.

File

webform_optionsmarkup.module
View source
<?php

/**
 * @file
 * Main module file.
 */

/**
 * Implements of hook_webform_component_info().
 */
function webform_optionsmarkup_webform_component_info() {
  $components = array();
  $components['optionsmarkup'] = array(
    'label' => t('Options with Markup'),
    'description' => t('Options with Markup'),
    'features' => array(
      'csv' => TRUE,
      'email' => TRUE,
      'email_address' => FALSE,
      'email_name' => FALSE,
      'required' => TRUE,
      'title_display' => TRUE,
      'title_inline' => TRUE,
      'conditional' => TRUE,
      'group' => FALSE,
      'spam_analysis' => FALSE,
      'attachment' => FALSE,
      'html' => TRUE,
    ),
    'file' => 'components/webform_optionsmarkup.inc',
  );
  return $components;
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Adds configuration options for this component to the webform admin page.
 */
function webform_optionsmarkup_form_webform_admin_settings_alter(&$form, &$form_state) {
  $form['optionsmarkup'] = array(
    '#type' => 'fieldset',
    '#title' => 'Webform Options Markup',
    '#description' => 'Webform options markup component settings',
  );
  $formats = filter_formats();
  $options = array();
  foreach ($formats as $format_id => $format) {
    $options[$format_id] = $format->name;
  }
  $form['optionsmarkup']['optionsmarkup_input_format'] = array(
    '#type' => 'select',
    '#title' => t('Text format for rendering option values'),
    '#description' => t('Select the Text Format to use when rendering the labels for option elements. Users must have permission to use this input format in order to edit this component.'),
    '#default_value' => variable_get('optionsmarkup_input_format', 'filtered_html'),
    '#options' => $options,
  );
}

/**
 * Determines which text format should be used for rendering the field.
 *
 * @return string
 *   The text format machine name to use.
 */
function webform_optionsmarkup_get_filter_format() {
  $format_id =& drupal_static(__FUNCTION__);
  if (!isset($format_id)) {
    $format_id = variable_get('optionsmarkup_input_format', 'filtered_html');
    if (empty($format_id)) {
      $format_id = filter_fallback_format();
    }
    $format = filter_format_load($format_id);
    if (!filter_access($format)) {
      $format_id = NULL;
      return $format_id;
    }
  }
  return $format_id;
}

/**
 * Passes the options through the enabled text format.
 *
 * @param string $string
 *   The string to filter.
 *
 * @param object $node
 *   The node to use for node token replacements.
 *
 * @param null $submission
 *   The submission to use for submission token replacements.
 *
 * @return string The filtered string.
 *   The filtered string.
 */
function webform_optionsmarkup_filter_content($string, $node = NULL, $submission = NULL) {
  $format_id = webform_optionsmarkup_get_filter_format();
  $string = webform_replace_tokens($string, $node, $submission);
  return check_markup($string, $format_id);
}

/**
 * FAPI process function to rename IDs attached to checkboxes and radios.
 *
 * @param array $element
 *  The form API element currently being processed.
 *
 * @return array
 *   The updated form api element.
 */
function webform_optionsmarkup_expand_select_ids($element) {
  $id = $element['#id'] = str_replace('_', '-', _webform_safe_name(strip_tags($element['#id'])));
  $delta = 0;
  foreach (element_children($element) as $key) {
    $delta++;

    // Convert the #id for each child to a safe name, regardless of key.
    $element[$key]['#id'] = $id . '-' . $delta;

    // Prevent scripts or CSS in the labels for each checkbox or radio.
    $element[$key]['#title'] = isset($element[$key]['#title']) ? webform_optionsmarkup_filter_content($element[$key]['#title']) : '';
  }
  return $element;
}

Functions

Namesort descending Description
webform_optionsmarkup_expand_select_ids FAPI process function to rename IDs attached to checkboxes and radios.
webform_optionsmarkup_filter_content Passes the options through the enabled text format.
webform_optionsmarkup_form_webform_admin_settings_alter Implements hook_form_FORM_ID_alter().
webform_optionsmarkup_get_filter_format Determines which text format should be used for rendering the field.
webform_optionsmarkup_webform_component_info Implements of hook_webform_component_info().