You are here

function theme_webform_node_form in Webform 5

Theme the node form. Use a table to organize the components.

Parameters

$form: The form array.

Return value

Formatted HTML form, ready for display

File

./webform.module, line 860

Code

function theme_webform_node_form($form) {
  $node = $form['#node'];
  $rows = array();
  if (is_array($node->webformcomponents) && !empty($node->webformcomponents)) {
    $component_tree = array();
    $page_count = 1;
    _webform_components_tree_build($node->webformcomponents, $component_tree, 0, $page_count);
    $component_tree = _webform_components_tree_sort($component_tree);

    // Build the table rows.
    function _webform_add_rows($cid, $component, $level, &$form, &$rows) {

      // Create presentable values.
      if (strlen($component['value']) > 30) {
        $component['value'] = substr($component['value'], 0, 30);
        $component['value'] .= "...";
      }
      $component['value'] = check_plain($component['value']);

      // Add padding to the radio label.
      $form['components']['selected_component'][$cid]['#title'] = '<span style="padding-left: ' . $level * 15 . 'px; padding-right: 20px;">' . $form['components']['selected_component'][$cid]['#title'] . '</span>';

      // Remove individual titles from the mandatory and weight fields.
      unset($form['components'][$cid]['mandatory']['#title']);
      unset($form['components'][$cid]['weight']['#title']);

      // Add each component to a table row.
      $rows[] = array(
        drupal_render($form['components']['selected_component'][$cid]),
        $component['type'],
        $component['value'] == "" ? "-" : $component['value'],
        drupal_render($form['components'][$cid]['mandatory']),
        drupal_render($form['components'][$cid]['weight']),
      );
      if (is_array($component['children'])) {
        foreach ($component['children'] as $cid => $component) {
          _webform_add_rows($cid, $component, $level + 1, $form, $rows);
        }
      }
    }
    foreach ($component_tree['children'] as $cid => $component) {
      _webform_add_rows($cid, $component, 0, $form, $rows);
    }
  }
  else {
    $rows[] = array(
      NULL,
      array(
        'data' => t("No Components, add a component below."),
        'colspan' => 5,
      ),
    );
  }
  $headers = array(
    array(
      'data' => t('Name'),
      'style' => 'padding-left: 30px',
    ),
    t('Type'),
    t('Value'),
    t('Mandatory'),
    t('Weight'),
  );
  $component_table .= theme('table', $headers, $rows);
  $form['components']['table'] = array(
    '#value' => $component_table,
  );
  return drupal_render($form);
}