function _webform_steps_generate in Webform steps 7
Generate the form-array for the webform step buttons.
1 call to _webform_steps_generate()
File
- ./
webform_steps.module, line 48
Code
function _webform_steps_generate($form, $form_state) {
$components = $form['#node']->webform['components'];
$pagebreak_names = array();
$fieldset_weights = array();
foreach ($components as $component) {
$page_num = $component['page_num'];
// use the fieldset with the lowest weight, omit nested fieldsets
if ($component['type'] === 'fieldset' && $component['pid'] === '0') {
if (!isset($fieldset_weights[$page_num]) || $component['weight'] < $fieldset_weights[$page_num]) {
$pagebreak_names[$page_num] = $component['name'];
$fieldset_weights[$page_num] = $component['weight'];
}
}
// use the title of the page break (will be overriden by any fieldset
// on the same step page)
if ($component['type'] === 'pagebreak') {
// set it only if not set already by a step name field
if (!isset($pagebreak_names[$page_num])) {
$pagebreak_names[$page_num] = $component['name'];
}
}
}
$count = $form['details']['page_count']['#value'];
$current = $form['details']['page_num']['#value'];
$finished = isset($form_state['steps_finished']) ? $form_state['steps_finished'] : 0;
$steps = array();
$button_builder = new WebformStepsButtonBuilder($current, $finished);
$use_ajax = module_exists('webform_ajax') && $form['#node']->webform['webform_ajax'];
if ($use_ajax) {
$button_builder
->activateAjax($form_state, $form);
}
for ($i = 1; $i <= $count; $i++) {
$title = isset($pagebreak_names[$i]) ? $pagebreak_names[$i] : t('No label');
$steps['btn-' . $i] = $button_builder
->buildButton($i, $title);
}
return $steps;
}