function _webform_edit_select in Webform 7.4
Same name and namespace in other branches
- 5.2 components/select.inc \_webform_edit_select()
- 5 components/select.inc \_webform_edit_select()
- 6.3 components/select.inc \_webform_edit_select()
- 6.2 components/select.inc \_webform_edit_select()
- 7.3 components/select.inc \_webform_edit_select()
Implements _webform_edit_component().
File
- components/
select.inc, line 53 - Webform module multiple select component.
Code
function _webform_edit_select($component) {
$form = array(
'#attached' => array(
'js' => array(
drupal_get_path('module', 'webform') . '/js/select-admin.js' => array(
'preprocess' => FALSE,
),
array(
'data' => array(
'webform' => array(
'selectOptionsUrl' => url('webform/ajax/options/' . $component['nid']),
),
),
'type' => 'setting',
),
),
),
);
// Default component if nested under a grid.
if (!isset($component['cid']) && $component['pid'] && ($node = node_load($component['nid'])) && ($parent = $node->webform['components'][$component['pid']]) && $parent['type'] == 'grid') {
$component['value'] = $parent['value'];
$component['extra']['items'] = $parent['extra']['options'];
$component['required'] = $parent['required'];
}
$other = array();
if ($info = _webform_select_options_info()) {
$options = array(
'' => t('None'),
);
foreach ($info as $name => $source) {
$options[$name] = $source['title'];
}
$other['options_source'] = array(
'#title' => t('Load a pre-built option list'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $component['extra']['options_source'],
'#description' => t('Use a pre-built list of options rather than entering options manually. Options will not be editable if using pre-built list.'),
'#parents' => array(
'extra',
'options_source',
),
'#weight' => 5,
);
}
if (module_exists('select_or_other')) {
$other['other_option'] = array(
'#type' => 'checkbox',
'#title' => t('Allow "Other..." option'),
'#default_value' => $component['extra']['other_option'],
'#description' => t('Check this option if you want to allow users to enter an option not on the list.'),
'#parents' => array(
'extra',
'other_option',
),
'#attributes' => array(
'class' => array(
'other-option-checkbox',
),
),
'#weight' => 2,
);
$other['other_text'] = array(
'#type' => 'textfield',
'#title' => t('Text for "Other..." option'),
'#default_value' => $component['extra']['other_text'],
'#description' => t('If allowing other options, enter text to be used for other-enabling option.'),
'#parents' => array(
'extra',
'other_text',
),
'#weight' => 3,
'#states' => array(
'visible' => array(
':input.other-option-checkbox' => array(
'checked' => TRUE,
),
),
),
);
}
if (module_exists('options_element')) {
$options = _webform_select_options($component, FALSE, FALSE);
$form['items'] = array(
'#type' => 'fieldset',
'#title' => t('Options'),
'#collapsible' => TRUE,
'#attributes' => array(
'class' => array(
'webform-options-element',
),
),
'#element_validate' => array(
'_webform_edit_validate_options',
),
'#weight' => 2,
);
$form['items']['options'] = array(
'#type' => 'options',
'#limit' => 500,
'#optgroups' => TRUE,
'#multiple' => $component['extra']['multiple'],
'#multiple_toggle' => t('Multiple'),
'#default_value' => $component['value'],
'#options' => $options,
'#options_readonly' => !empty($component['extra']['options_source']),
'#key_type' => 'mixed',
'#key_type_toggle' => t('Customize keys (Advanced)'),
'#key_type_toggled' => $component['extra']['custom_keys'],
'#default_value_pattern' => '^%.+\\[.+\\]$',
'#weight' => 1,
);
$form['items']['options']['option_settings'] = $other;
}
else {
$form['extra']['items'] = array(
'#type' => 'textarea',
'#title' => t('Options'),
'#default_value' => $component['extra']['items'],
'#description' => t('<strong>Key-value pairs MUST be specified as "safe_key|Some readable option"</strong>. Use of only alphanumeric characters and underscores is recommended in keys. One option per line. Option groups may be specified with <Group Name>. <> can be used to insert items at the root of the menu after specifying a group.') . ' ' . theme('webform_token_help'),
'#cols' => 60,
'#rows' => 5,
'#weight' => 0,
'#required' => TRUE,
'#wysiwyg' => FALSE,
'#element_validate' => array(
'_webform_edit_validate_select',
),
);
if (!empty($component['extra']['options_source'])) {
$form['extra']['items']['#attributes'] = array(
'readonly' => 'readonly',
);
}
$form['extra'] = array_merge($form['extra'], $other);
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Default value'),
'#default_value' => $component['value'],
'#description' => t('The default value of the field identified by its key. For multiple selects use commas to separate multiple defaults.') . ' ' . theme('webform_token_help'),
'#size' => 60,
'#maxlength' => 1024,
'#weight' => 0,
);
$form['extra']['multiple'] = array(
'#type' => 'checkbox',
'#title' => t('Multiple'),
'#default_value' => $component['extra']['multiple'],
'#description' => t('Check this option if the user should be allowed to choose multiple values.'),
'#weight' => 0,
);
}
$form['display']['aslist'] = array(
'#type' => 'checkbox',
'#title' => t('Listbox'),
'#default_value' => $component['extra']['aslist'],
'#description' => t('Check this option if you want the select component to be displayed as a select list box instead of radio buttons or checkboxes. Option groups (nested options) are only supported with listbox components.'),
'#parents' => array(
'extra',
'aslist',
),
);
$form['display']['empty_option'] = array(
'#type' => 'textfield',
'#title' => t('Empty option'),
'#default_value' => $component['extra']['empty_option'],
'#size' => 60,
'#maxlength' => 255,
'#description' => t('The list item to show when no default is provided. Leave blank for "- None -" or "- Select -".'),
'#parents' => array(
'extra',
'empty_option',
),
'#states' => array(
'visible' => array(
':input[name="extra[aslist]"]' => array(
'checked' => TRUE,
),
':input[name="extra[multiple]"]' => array(
'checked' => FALSE,
),
':input[name="value"]' => array(
'filled' => FALSE,
),
),
),
);
$form['display']['optrand'] = array(
'#type' => 'checkbox',
'#title' => t('Randomize options'),
'#default_value' => $component['extra']['optrand'],
'#description' => t('Randomizes the order of the options when they are displayed in the form.'),
'#parents' => array(
'extra',
'optrand',
),
);
return $form;
}