You are here

function _webform_conditional_expand_value_forms in Webform 7.4

Expand out all the value forms that could potentially be used.

These forms are added to the page via JavaScript and swapped in only when needed. Because the user may change the source and operator at any time, all these forms need to be generated ahead of time and swapped in. This could have been done via AJAX, but having all forms available makes for a faster user experience.

Added to the JavaScript settings is conditionalValues which contains an array settings suitable for adding to the page via JavaScript. This array contains the following keys:

  • operators: An array containing a map of data types, operators, and form keys. This array is structured as follows:
-(sources[$source_key] = array(
  'data_type' => $data_type,
));
$operators[$data_type][$operator] = array(
  'form' => $form_key,
);
  • forms[$form_key]: A string representing an HTML form for an operator.
  • forms[$form_key][$source]: Or instead of a single form for all components, if each component requires its own form, key each component by its source value (currently always the component ID).

Parameters

object $node: The Webform node for which these forms are being generated.

2 calls to _webform_conditional_expand_value_forms()
webform_conditionals_form in includes/webform.conditionals.inc
Form builder; Provide the form for adding conditionals to a webform node.
webform_conditionals_form_validate in includes/webform.conditionals.inc
Validate handler for webform_conditionals_form().

File

includes/webform.conditionals.inc, line 641
Form elements and menu callbacks to provide conditional handling in Webform.

Code

function _webform_conditional_expand_value_forms($node) {
  $operators = webform_conditional_operators();
  $data = array();
  foreach ($operators as $data_type => $operator_info) {
    foreach ($operator_info as $operator => $data_operator_info) {
      $data['operators'][$data_type][$operator]['form'] = 'default';
      if (isset($data_operator_info['form callback'])) {
        $form_callback = $data_operator_info['form callback'];
        $data['operators'][$data_type][$operator]['form'] = $form_callback;
        if ($form_callback !== FALSE && !isset($data['forms'][$form_callback])) {
          $data['forms'][$form_callback] = $form_callback($node);
        }
      }
    }
  }
  foreach ($node->webform['components'] as $cid => $component) {
    if (webform_component_feature($component['type'], 'conditional')) {
      $data['sources'][$cid]['data_type'] = webform_component_property($component['type'], 'conditional_type');
    }
  }
  drupal_add_js(array(
    'webform' => array(
      'conditionalValues' => $data,
    ),
  ), 'setting');
}