You are here

function webform_component_list in Webform 7.4

Same name and namespace in other branches
  1. 6.3 includes/webform.components.inc \webform_component_list()
  2. 7.3 includes/webform.components.inc \webform_component_list()

Create a list of components suitable for a select list.

Parameters

$node: The webform node.

$component_filter: Either an array of components, or a string containing a feature name (csv, email, required, conditional) on which this list of components will be restricted.

$prefix_group: TRUE to indent with a hyphen, or 'path" to Prepend enclosing group (for example, fieldset) name(s)

$pagebreak_groups: Determine if pagebreaks should be converted to option groups in the returned list of options.

Return value

array An array of options.

9 calls to webform_component_list()
WebformComponentsTestCase::testWebformComponents in tests/WebformComponentsTestCase.test
Webform module component tests.
webform_analysis_components_form in includes/webform.report.inc
Form for selecting which components should be shown on the analysis page.
webform_conditionals_form in includes/webform.conditionals.inc
Form builder; Provide the form for adding conditionals to a webform node.
webform_configure_form in includes/webform.pages.inc
Main configuration form for editing a webform node.
webform_emails_form in includes/webform.emails.inc
Overview form of all components for this webform.

... See full list

File

includes/webform.components.inc, line 1050
Webform module component handling.

Code

function webform_component_list($node, $component_filter = NULL, $prepend_group = TRUE, $pagebreak_groups = FALSE) {
  $options = array();
  $page_names = array();
  $parent_names = array();
  $components = is_array($component_filter) ? $component_filter : $node->webform['components'];
  $feature = is_string($component_filter) ? $component_filter : NULL;
  foreach ($components as $cid => $component) {

    // If this component is a group (for example, fieldset), then remember its name, including any parents.
    if ($prepend_group && webform_component_feature($component['type'], 'group')) {
      $parent_names[$cid] = ($component['pid'] ? $parent_names[$component['pid']] : '') . ($prepend_group === 'path' ? $component['name'] . ': ' : '-');
    }
    $page_num = $component['page_num'];

    // If this component is a pagebreak, then generate an option group, ensuring a unique name.
    if ($pagebreak_groups && $component['type'] == 'pagebreak') {
      $page_name = $component['name'];

      // When a $page_name consists only of digits, append a space to ensure it
      // is never the same as a $cid.
      if ((string) $page_name === (string) (int) $page_name) {
        $page_name .= ' ';
      }
      $copy = 1;
      while (in_array($page_name, $page_names)) {
        $page_name = $component['name'] . '_' . ++$copy;
      }
      $page_names[$page_num] = $page_name;
    }

    // If this component should be included in the options, add it with any prefix, in a page group, as needed.
    if (!isset($feature) || webform_component_feature($component['type'], $feature) || $prepend_group === TRUE) {
      $prefix = $prepend_group && $component['pid'] ? $parent_names[$component['pid']] : '';
      if ($pagebreak_groups && $page_num > 1) {
        $options[$page_names[$page_num]][$cid] = $prefix . $component['name'];
      }
      else {
        $options[$cid] = $prefix . $component['name'];
      }
    }
  }
  return $options;
}