function template_preprocess_webform_components_form in Webform 7.4
Preprocess variables for theming the webform components form.
File
- includes/
webform.components.inc, line 157 - Webform module component handling.
Code
function template_preprocess_webform_components_form(&$variables) {
$form = $variables['form'];
$form['components']['#attached']['library'][] = array(
'webform',
'admin',
);
// @todo Attach these. See http://drupal.org/node/732022.
drupal_add_tabledrag('webform-components', 'order', 'sibling', 'webform-weight');
drupal_add_tabledrag('webform-components', 'match', 'parent', 'webform-pid', 'webform-pid', 'webform-cid');
$node = $form['#node'];
$header = array(
t('Label'),
t('Form key'),
t('Type'),
t('Value'),
t('Required'),
t('Weight'),
array(
'data' => t('Operations'),
'colspan' => 3,
),
);
$rows = array();
// Add a row containing form elements for a new item.
unset($form['add']['name']['#title'], $form['add_type']['#description']);
$form['add']['name']['#attributes']['placeholder'] = t('New component name');
$form['add']['cid']['#attributes']['class'][] = 'webform-cid';
$form['add']['pid']['#attributes']['class'][] = 'webform-pid';
$form['add']['weight']['#attributes']['class'][] = 'webform-weight';
$row_data = array(
array(
'data' => drupal_render($form['add']['name']),
'class' => array(
'webform-component-name',
),
'colspan' => 2,
),
array(
'data' => drupal_render($form['add']['type']),
'class' => array(
'webform-component-type',
),
),
array(
'data' => '',
'class' => array(
'webform-component-value',
),
),
array(
'data' => drupal_render($form['add']['required']),
'class' => array(
'webform-component-required',
'checkbox',
),
),
array(
'data' => drupal_render($form['add']['cid']) . drupal_render($form['add']['pid']) . drupal_render($form['add']['weight']),
),
array(
'colspan' => 3,
'data' => drupal_render($form['add']['add']),
'class' => array(
'webform-component-add',
),
),
);
$add_form = array(
'data' => $row_data,
'class' => array(
'draggable',
'webform-add-form',
'tabledrag-leaf',
),
);
if (!empty($node->webform['components'])) {
$component_tree = array();
$page_count = 1;
_webform_components_tree_build($node->webform['components'], $component_tree, 0, $page_count);
$component_tree = _webform_components_tree_sort($component_tree);
// Build the table rows recursively.
foreach ($component_tree['children'] as $cid => $component) {
_webform_components_form_rows($node, $cid, $component, 0, $form, $rows, $add_form);
}
}
else {
$rows[] = array(
array(
'data' => t('No Components, add a component below.'),
'colspan' => 9,
),
);
// When there are no components, tabledrag.js will look to the add component
// row to locate the weight column. Because of the name/form_key colspan
// it will mis-count the columns and locate the Required column instead of
// the Weight column.
unset($add_form['data'][0]['colspan']);
array_splice($add_form['data'], 1, 0, ' ');
}
// Append the add form if not already printed.
if ($add_form) {
$rows[] = $add_form;
}
$variables['rows'] = $rows;
$variables['header'] = $header;
$variables['form'] = $form;
}