array('configForm' => array($config_id))), 'setting');
}
$config = hierarchical_select_common_config_get($config_id, $defaults_override);
$args = array(
'!item' => $strings['item'],
'!items' => $strings['items'],
'!entity' => $strings['entity'],
'!entities' => $strings['entities'],
'!hierarchy' => $strings['hierarchy'],
'!hierarchies' => $strings['hierarchies']
);
$form = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => t('Hierarchical Select configuration'),
'#attributes' => array(
'class' => 'hierarchical-select-config-form',
'id' => 'hierarchical-select-config-form-'. $config_id,
),
);
$form['config_id'] = array('#type' => 'value', '#value' => $config_id);
// TODO: really make this a *live* preview, i.e. refresh the preview on each
// change in the form. This cannot be done easily in Drupal 5, so let's do
// so in Drupal 6. See cfg.livePreview in common_config_form.js.
$form['live_preview'] = array(
'#type' => 'fieldset',
'#title' => t('Preview'),
'#description' => t('This is what the Hierarchical Select will look like with your current configuration.'),
'#collapsible' => FALSE,
'#attributes' => array('class' => 'live-preview'),
);
$form['live_preview']['example'] = array(
'#type' => 'hierarchical_select',
'#required' => $preview_is_required,
'#title' => t('Preview'),
'#description' => t('The description.'),
// Skip all validation.
'#validated' => TRUE,
);
hierarchical_select_common_config_apply($form['live_preview']['example'], $config_id, array_merge($defaults_override, array('module' => $module, 'params' => $params)));
$form['save_lineage'] = array(
'#type' => 'radios',
'#title' => t('Save lineage'),
'#options' => array(
1 => t('Save !item lineage', $args),
0 => t('Save only the deepest !item', $args),
),
'#default_value' => $config['save_lineage'],
'#description' => t(
'Saving the !item lineage means saving the the !item itself and all
its ancestors.',
$args
),
);
$form['enforce_deepest'] = array(
'#type' => 'radios',
'#title' => t('Level choice'),
'#options' => array(
1 => t('Force the user to choose a !item from a deepest level', $args),
0 => t('Allow the user to choose a !item from any level', $args),
),
'#default_value' => $config['enforce_deepest'],
'#description' => t(
'This setting determines from which level in the !hierarchy tree a
user can select a !item.',
$args
),
'#attributes' => array('class' => 'enforce-deepest'),
);
if (module_hook($module, 'hierarchical_select_entity_count')) {
$form['entity_count'] = array(
'#type' => 'radios',
'#title' => t('Display the !entity count', $args),
'#description' => t(
'When enabled, the user will see the number of !entities that match
the current !item listed between brackets.',
$args
),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $config['entity_count'],
'#attributes' => array('class' => 'entity-count'),
);
$form['require_entity'] = array(
'#type' => 'radios',
'#title' => t('Require associated !entity', $args),
'#description' => t(
'When enabled, !items will only be displayed when they are associated
with at least one !entity, or if one of their child !items are
associated with at least one !entity.',
$args
),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $config['require_entity'],
'#attributes' => array('class' => 'require-entity'),
);
}
$form['resizable'] = array(
'#type' => 'radios',
'#title' => t('Resizable'),
'#description' => t(
"When enabled, a handle appears below the Hierarchical Select to allow
the user to dynamically resize it. Double clicking will toggle between
the smallest and a sane 'big size'."
),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $config['resizable'],
'#attributes' => array('class' => 'resizable'),
);
$form['level_labels'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => t('Level labels'),
'#description' => t(
'When the user is allowed to choose a !item from any level in the
Level choice setting, you can enter a label for each
level.
However, when the user is only allowed to choose a !item from the
deepest level, then you can only enter a label for the root
level.',
$args
),
'#collapsible' => TRUE,
);
$form['level_labels']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable level labels'),
'#default_value' => $config['level_labels']['status'],
'#attributes' => array('class' => 'level-labels-status'),
);
for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
$form['level_labels']['labels'][$depth] = array(
'#type' => 'textfield',
'#size' => 20,
'#maxlength' => 255,
'#default_value' => $config['level_labels']['labels'][$depth],
'#attributes' => array('class' => 'level-label'),
);
}
$form['level_labels']['#theme'] = 'hierarchical_select_common_config_form_level_labels';
$form['level_labels']['#strings'] = $strings;
$form['dropbox'] = array(
'#type' => 'fieldset',
'#title' => t('Dropbox settings'),
'#description' => t('The dropbox allows the user to make multiple selections.'),
'#collapsible' => TRUE,
);
$form['dropbox']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable the dropbox'),
'#default_value' => $config['dropbox']['status'],
'#attributes' => array('class' => 'dropbox-status'),
);
$form['dropbox']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The title you enter here appears above the dropbox.'),
'#size' => 20,
'#maxlength' => 255,
'#default_value' => $config['dropbox']['title'],
'#attributes' => array('class' => 'dropbox-title'),
);
$form['dropbox']['limit'] = array(
'#type' => 'textfield',
'#title' => t('Limit the number of selections'),
'#description' => t(
'Limits the number of selections that can be added to the dropbox.
0 means no limit.
Note: the "Save !item lineage" option has no effect on this, even if
a lineage consists of 3 !items, this will count as only one selection
in the dropbox.',
$args
),
'#size' => 5,
'#maxlength' => 5,
'#default_value' => $config['dropbox']['limit'],
'#attributes' => array('class' => 'dropbox-limit'),
);
$form['dropbox']['reset_hs'] = array(
'#type' => 'radios',
'#title' => t('Reset selection of hierarchical select'),
'#description' => t(
'This setting determines what will happen to the hierarchical select
when the user has added a selection to the dropbox.'
),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $config['dropbox']['reset_hs'],
'#attributes' => array('class' => 'dropbox-reset-hs'),
);
if (module_hook($module, 'hierarchical_select_create_item')) {
$form['editability'] = array(
'#type' => 'fieldset',
'#title' => t('Editability settings'),
'#description' => t(
'You can allow the user to add new !items to this
!hierarchy through Hierarchical Select.',
$args
),
'#collapsible' => TRUE,
);
$form['editability']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Allow creation of new !items', $args),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $config['editability']['status'],
'#attributes' => array('class' => 'editability-status'),
);
for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
$form['editability']['item_types'][$depth] = array(
'#type' => 'textfield',
'#size' => 20,
'#maxlength' => 255,
'#default_value' => $config['editability']['item_types'][$depth],
'#attributes' => array('class' => 'editability-item-type'),
);
}
for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
$form['editability']['allowed_levels'][$depth] = array(
'#type' => 'checkbox',
'#default_value' => (isset($config['editability']['allowed_levels'][$depth])) ? $config['editability']['allowed_levels'][$depth] : 1,
);
}
$form['editability']['allow_new_levels'] = array(
'#type' => 'checkbox',
'#title' => t('Allow creation of new levels'),
'#default_value' => $config['editability']['allow_new_levels'],
'#description' => t(
'Allow the user to create child !items for !items that do not yet have
children.',
$args
),
'#attributes' => array('class' => 'editability-allow-new-levels'),
);
$form['editability']['max_levels'] = array(
'#type' => 'select',
'#title' => t('Maximum number of levels allowed'),
'#options' => array(
0 => t('0 (no limit)'), 1, 2, 3, 4, 5, 6, 7, 8, 9
),
'#default_value' => $config['editability']['max_levels'],
'#description' => t(
'When the user is allowed to create new levels, this option prevents
the user from creating extremely deep !hierarchies.',
$args
),
'#attributes' => array('class' => 'editability-max-levels'),
);
$form['editability']['#theme'] = 'hierarchical_select_common_config_form_editability';
$form['editability']['#strings'] = $strings;
}
return $form;
}
/**
* Themeing function to render the level_labels settings as a table.
*/
function theme_hierarchical_select_common_config_form_level_labels($form) {
// Recover the stored strings.
$strings = $form['#strings'];
$output = '';
$header = array(t('Level'), t('Label'));
$rows = array();
$output .= drupal_render($form['status']);
$output .= '
'; $output .= t('There are no levels yet in this !hierarchy!', array('!hierarchy' => $strings['hierarchy'])); $output .= '
'; } $output .= ''; $output .= t('There are no levels yet in this !hierarchy!', array('!hierarchy' => $strings['hierarchy'])); $output .= '
'; } $output .= '