function msnf_step_overview_form in Multistep Nodeform 6
Menu callback; listing of steps for a content type.
Allows steps to be reordered and fields to be associated into steps using JS drag-n-drop.
1 string reference to 'msnf_step_overview_form'
- msnf_menu in ./
msnf.module - Implementation of hook_menu().
File
- includes/
msnf.admin.inc, line 13
Code
function msnf_step_overview_form(&$form_state, $type_name) {
// Load necessary functions for form steps.
module_load_include('inc', 'msnf', 'includes/msnf.steps');
// When displaying the form, make sure the list of fields is up-to-date.
if (empty($form_state['post'])) {
msnf_clear_type_cache();
}
// Gather type information.
$type = msnf_content_types($type_name);
$field_types = _msnf_content_field_types();
// Non-CCK fields (such as "title", "body", etc.).
$extra = $type['extra'];
// CCK-fields.
$fields = $type['fields'];
// Field groups.
$groups = array();
if (module_exists('fieldgroup')) {
$groups = fieldgroup_groups($type['type']);
$group_types = fieldgroup_types();
}
$steps = $step_options = $step_types = array();
$steps = msnf_steps($type['type']);
$step_types = msnf_step_types();
$step_options = _msnf_steps_label($type['type']);
// Add the ability to group fields under the newly created row.
$step_options['_add_new_step'] = '_add_new_step';
// Add group names to step options so we can move fields into groups.
// $groups is empty if fieldgroup.module is not enabled.
foreach ($groups as $group_name => $group) {
$step_options[$group_name] = t($group['label']);
}
// Store the default weights as we meet them, to be able to put the
//'add new' rows after them.
$weights = array();
$form = array(
'#tree' => TRUE,
'#type_name' => $type['type'],
'#fields' => array_keys($fields),
'#steps' => array_keys($steps),
'#extra' => array_keys($extra),
'#groups' => array_keys($groups),
'#field_rows' => array(),
'#group_rows' => array(),
'#step_rows' => array(),
);
// Extra-Fields (non-CCK).
foreach ($extra as $name => $field) {
$weight = $field['weight'];
$label = $field['label'];
$field_name = $name;
$form[$name] = array(
'label' => array(
'#value' => check_plain($label),
),
'field_name' => array(
'#value' => $field['field_name'],
),
'type' => array(
'#value' => $field_types[$field['type']]['label'],
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'parent' => array(
'#type' => 'select',
'#options' => $step_options,
'#default_value' => '',
),
'prev_parent' => array(
'#type' => 'hidden',
'#value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $field_name,
),
'#leaf' => TRUE,
'#row_type' => 'field',
'field' => array(
'#type' => 'value',
'#value' => $field,
),
);
$form['#field_rows'][] = $name;
$weights[] = $weight;
}
// Fields (CCK).
foreach ($fields as $name => $field) {
$weight = $field['widget']['weight'];
$label = $field['widget']['label'];
$field_name = $field['field_name'];
$form[$name] = array(
'label' => array(
'#value' => check_plain($label),
),
'field_name' => array(
'#value' => $field['field_name'],
),
'type' => array(
'#value' => t($field_types[$field['type']]['label']),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'parent' => array(
'#type' => 'select',
'#options' => $step_options,
'#default_value' => '',
),
'prev_parent' => array(
'#type' => 'hidden',
'#value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $field_name,
),
'#leaf' => TRUE,
'#row_type' => 'field',
'field' => array(
'#type' => 'value',
'#value' => $field,
),
);
$form['#field_rows'][] = $name;
$weights[] = $weight;
}
// Groups.
foreach ($groups as $name => $group) {
$weight = $group['weight'];
$form[$name] = array(
'label' => array(
'#value' => check_plain($group['label']),
),
'group_name' => array(
'#value' => $group['group_name'],
),
'group_type' => array(
'#value' => t($group_types[$group['group_type']]),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'parent' => array(
'#type' => 'select',
'#options' => $step_options,
'#default_value' => '',
),
'prev_parent' => array(
'#type' => 'hidden',
'#value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $group['group_name'],
),
'#leaf' => FALSE,
'#row_type' => 'group',
'group' => array(
'#type' => 'value',
'#value' => $group,
),
);
// Adjust child fields rows.
foreach ($group['fields'] as $field_name => $field) {
$form[$field_name]['parent']['#default_value'] = $name;
$form[$field_name]['prev_parent']['#value'] = $name;
}
$form['#group_rows'][] = $name;
$weights[] = $weight;
}
// Steps.
foreach ($steps as $name => $step) {
$weight = $step['weight'];
$form[$name] = array(
'label' => array(
'#value' => check_plain($step['label']),
),
'step_name' => array(
'#value' => $step['step_name'],
),
'step_type' => array(
'#value' => t($step_types[$step['step_type']]),
),
'configure' => array(
'#value' => l(t('Configure'), 'admin/content/node-type/' . $type['url_str'] . '/steps/' . $step['step_name']),
),
'remove' => array(
'#value' => l(t('Remove'), 'admin/content/node-type/' . $type['url_str'] . '/steps/' . $step['step_name'] . '/remove'),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'parent' => array(
'#type' => 'hidden',
'#default_value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $step['step_name'],
),
'#root' => TRUE,
'#row_type' => 'step',
'step' => array(
'#type' => 'value',
'#value' => $step,
),
);
// Adjust child fields rows.
foreach ($step['fields'] as $field_name => $field) {
if (strpos($form[$field_name]['parent']['#default_value'], 'group_') > -1) {
// Field is child of a fieldgroup so do not change its parent!
}
else {
$form[$field_name]['parent']['#default_value'] = $name;
$form[$field_name]['prev_parent']['#value'] = $name;
}
}
// Adjust child groups rows.
foreach ($step['groups'] as $group_name => $group) {
$form[$group_name]['parent']['#default_value'] = $name;
$form[$group_name]['prev_parent']['#value'] = $name;
}
$form['#step_rows'][] = $name;
$weights[] = $weight;
}
$weight = max($weights) + 1;
// Additional row : add new step.
if (!empty($step_types)) {
$weight++;
$name = '_add_new_step';
$form[$name] = array(
'label' => array(
'#type' => 'textfield',
'#size' => 15,
'#description' => t('Label'),
),
'step_name' => array(
'#type' => 'textfield',
// This field should stay LTR even for RTL languages.
'#field_prefix' => '<span dir="ltr">step_',
'#field_suffix' => '</span>‎',
// Left-To-Right-Marker
'#attributes' => array(
'dir' => 'ltr',
),
'#size' => 15,
// Step names are limited to 32 characters including the 'step_'
// prefix which is 6 characters long.
'#maxlength' => 26,
'#description' => t('Step name (a-z, 0-9, _)'),
),
'step_option' => array(
'#type' => 'hidden',
'#value' => '',
),
'step_type' => array(
'#type' => 'hidden',
'#value' => 'standard',
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'parent' => array(
'#type' => 'hidden',
'#default_value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $name,
),
'#root' => TRUE,
'#add_new' => TRUE,
'#row_type' => 'add_new_step',
);
if (count($step_types) > 1) {
$form[$name]['step_type'] = array(
'#type' => 'select',
'#description' => t('Type of step.'),
'#options' => $step_types,
'#default_value' => 'standard',
);
}
$form['#step_rows'][] = $name;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}