function _webform_components_form_rows in Webform 7.4
Recursive function for nesting components into a table.
See also
preprocess_webform_components_form()
1 call to _webform_components_form_rows()
- template_preprocess_webform_components_form in includes/
webform.components.inc - Preprocess variables for theming the webform components form.
File
- includes/
webform.components.inc, line 222 - Webform module component handling.
Code
function _webform_components_form_rows($node, $cid, $component, $level, &$form, &$rows, &$add_form) {
// Create presentable values.
$form_key = truncate_utf8($component['form_key'], 30, FALSE, TRUE);
$value = truncate_utf8($component['value'], 30, TRUE, TRUE, 20);
// Remove individual titles from the required and weight fields.
unset($form['components'][$cid]['required']['#title']);
unset($form['components'][$cid]['pid']['#title']);
unset($form['components'][$cid]['weight']['#title']);
// Add special classes for weight and parent fields.
$form['components'][$cid]['cid']['#attributes']['class'] = array(
'webform-cid',
);
$form['components'][$cid]['pid']['#attributes']['class'] = array(
'webform-pid',
);
$form['components'][$cid]['weight']['#attributes']['class'] = array(
'webform-weight',
);
// Build indentation for this row.
$indents = '';
for ($n = 1; $n <= $level; $n++) {
$indents .= '<div class="indentation"> </div>';
}
// Add each component to a table row.
$row_data = array(
array(
'data' => $indents . filter_xss($component['name']),
'class' => array(
'webform-component-name',
),
),
array(
'data' => check_plain($form_key),
'class' => array(
'webform-component-formkey',
),
) + ((string) $component['form_key'] === (string) $form_key ? array() : array(
'title' => $component['form_key'],
)),
array(
'data' => $form['add']['type']['#options'][$component['type']],
'class' => array(
'webform-component-type',
),
),
array(
'data' => $value == '' ? '-' : check_plain($value),
'class' => array(
'webform-component-value',
),
) + ($component['value'] == $value ? array() : array(
'title' => $component['value'],
)),
array(
'data' => drupal_render($form['components'][$cid]['required']),
'class' => array(
'webform-component-required',
'checkbox',
),
),
array(
'data' => drupal_render($form['components'][$cid]['cid']) . drupal_render($form['components'][$cid]['pid']) . drupal_render($form['components'][$cid]['weight']),
),
array(
'data' => l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array(
'query' => drupal_get_destination(),
)),
'class' => array(
'webform-component-edit',
),
),
array(
'data' => l(t('Clone'), 'node/' . $node->nid . '/webform/components/' . $cid . '/clone', array(
'query' => drupal_get_destination(),
)),
'class' => array(
'webform-component-clone',
),
),
array(
'data' => l(t('Delete'), 'node/' . $node->nid . '/webform/components/' . $cid . '/delete', array(
'query' => drupal_get_destination(),
)),
'class' => array(
'webform-component-delete',
),
),
);
$row_class = array(
'draggable',
);
if (!webform_component_feature($component['type'], 'group')) {
$row_class[] = 'tabledrag-leaf';
}
if ($component['type'] == 'pagebreak') {
$row_class[] = 'tabledrag-root';
$row_class[] = 'webform-pagebreak';
$row_data[0]['class'][] = 'webform-pagebreak';
}
$rows[] = array(
'data' => $row_data,
'class' => $row_class,
'data-cid' => $cid,
);
if (isset($component['children']) && is_array($component['children'])) {
foreach ($component['children'] as $cid => $component) {
_webform_components_form_rows($node, $cid, $component, $level + 1, $form, $rows, $add_form);
}
}
// Add the add form if this was the last edited component.
if (isset($_GET['cid']) && $component['cid'] == $_GET['cid'] && $add_form) {
$add_form['data'][0]['data'] = $indents . $add_form['data'][0]['data'];
$rows[] = $add_form;
$add_form = FALSE;
}
}