You are here

function webform_component_list in Webform 6.3

Same name and namespace in other branches
  1. 7.4 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.

$indent: Indent components placed under fieldsets with hyphens.

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

5 calls to webform_component_list()
webform_component_edit_form in includes/webform.components.inc
Form to configure a webform component.
webform_emails_form in includes/webform.emails.inc
Overview form of all components for this webform.
webform_email_edit_form in includes/webform.emails.inc
Form for configuring an e-mail setting and template.
webform_results_download_form in includes/webform.report.inc
Form to configure the download of CSV files.
webform_results_export in includes/webform.report.inc
Generate a Excel-readable CSV file containing all submissions for a Webform.

File

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

Code

function webform_component_list($node, $component_filter = NULL, $indent = TRUE, $optgroups = FALSE) {
  $options = array();
  $page_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 (!isset($feature) || webform_component_feature($component['type'], $feature) || $indent && webform_component_feature($component['type'], 'group')) {
      $prefix = '';
      $page_num = $component['page_num'];
      $page_index = 'p' . $page_num;
      if ($indent && ($parent_count = count(webform_component_parent_keys($node, $component)) - 1)) {
        $prefix = str_repeat('-', $parent_count);
      }
      if ($optgroups && $component['type'] == 'pagebreak') {
        $page_names[$page_index] = $component['name'];
      }
      elseif ($optgroups && $page_num > 1) {
        $options[$page_index][$cid] = $prefix . $component['name'];
      }
      else {
        $options[$cid] = $prefix . $component['name'];
      }
    }
  }

  // Convert page breaks into optgroups.
  if ($optgroups) {
    $grouped_options = $options;
    $options = array();
    foreach ($grouped_options as $key => $values) {
      if (is_array($values) && isset($page_names[$key])) {
        $options[$page_names[$key]] = $values;
      }
      else {
        $options[$key] = $values;
      }
    }
  }
  return $options;
}