function _webform_edit_name in Name Field 7
Implements Webform callback _webform_edit_COMPONENT().
File
- includes/
webform.components.inc, line 43 - Name Field module name component for the Webform module.
Code
function _webform_edit_name($name) {
$components = _name_translations();
$format_options = array(
'default' => t('System default'),
) + name_get_custom_format_options();
$form['extra']['display_format'] = array(
'#type' => 'select',
'#title' => t('Display format'),
'#default_value' => $name['extra']['display_format'],
'#required' => TRUE,
'#options' => $format_options,
);
$form['extra']['table_format'] = array(
'#type' => 'select',
'#title' => t('Table format'),
'#default_value' => $name['extra']['table_format'],
'#required' => TRUE,
'#options' => $format_options,
);
// Add an option for individual components. This machine name is not valid.
$format_options += array(
'separate components' => t('As separate components'),
);
$form['extra']['csv_format'] = array(
'#type' => 'select',
'#title' => t('Export format'),
'#default_value' => $name['extra']['csv_format'],
'#required' => TRUE,
'#options' => $format_options,
);
$form['extra']['enabled_components'] = array(
'#type' => 'checkboxes',
'#title' => t('Enabled components'),
'#default_value' => $name['extra']['enabled_components'],
'#required' => TRUE,
'#element_validate' => array(
'_name_field_minimal_component_requirements',
),
'#description' => t('Only the selected components will be rendered on the webform.'),
'#options' => $components,
);
// Most options are stored in the "extra" array, which stores any settings
// unique to a particular name type.
$form['extra']['minimum_components'] = array(
'#type' => 'checkboxes',
'#title' => t('Minimum components'),
'#default_value' => $name['extra']['minimum_components'],
'#required' => TRUE,
'#element_validate' => array(
'_name_field_minimal_component_requirements',
),
'#description' => t('The minimal set of components required before the field is considered completed enough to save.'),
'#options' => $components,
);
$user_field_name = variable_get('name_user_preferred', '');
$user_field = $user_field_name ? field_info_instance('user', $user_field_name, 'user') : NULL;
$form['extra']['use_real_name'] = array(
'#type' => 'checkbox',
'#title' => t('Use users real name field as default'),
'#default_value' => $user_field ? $name['extra']['use_real_name'] : 0,
'#description' => t('This option is only available if you have selected a name field to override the users login name.'),
'#disabled' => !$user_field,
);
foreach ($components as $key => $label) {
$form['extra']['components'][$key] = array(
'#type' => 'fieldset',
'#title' => t('@label component seettings', array(
'@label' => $label,
)),
);
// @todo .
$type = $key == 'title' || $key == 'generational' ? 'select' : 'textfield';
$form['extra']['components'][$key]['type'] = array(
'#type' => 'value',
'#value' => $type,
);
$form['extra']['components'][$key]['title'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $name['extra']['components'][$key]['title'],
);
// New feature. This prevents PHP notices.
if (!isset($name['extra']['components'][$key]['default_value'])) {
$name['extra']['components'][$key]['default_value'] = '';
}
$form['extra']['components'][$key]['default_value'] = array(
'#type' => 'textfield',
'#title' => t('Default value'),
'#default_value' => $name['extra']['components'][$key]['default_value'],
'#description' => t('Tokens are allowed. Real name support will override this setting.'),
);
$form['extra']['components'][$key]['title_display'] = array(
'#type' => 'select',
'#title' => t('Component title display'),
'#default_value' => $name['extra']['components'][$key]['title_display'],
'#options' => array(
'title' => t('above'),
'description' => t('below'),
'placeholder' => t('placeholder'),
'none' => t('hidden'),
),
);
$form['extra']['components'][$key]['size'] = array(
'#type' => 'textfield',
'#title' => t('HTML size property'),
'#default_value' => $name['extra']['components'][$key]['size'],
'#size' => 10,
'#element_validate' => array(
'_element_validate_integer_positive',
),
);
$form['extra']['components'][$key]['inline_css'] = array(
'#type' => 'textfield',
'#title' => t('Additional inline styles'),
'#default_value' => $name['extra']['components'][$key]['inline_css'],
);
$form['extra']['components'][$key]['max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum length'),
'#default_value' => empty($name['extra']['components'][$key]['max_length']) ? 255 : $name['extra']['components'][$key]['max_length'],
'#required' => TRUE,
'#size' => 10,
'#element_validate' => array(
'_element_validate_integer_positive',
),
);
if ($key == 'title' || $key == 'generational') {
$options = implode("\n", array_filter(explode("\n", $name['extra']['components'][$key]['options'])));
$form['extra']['components'][$key]['options'] = array(
'#type' => 'textarea',
'#name_component' => $key,
'#title' => t('Options'),
'#default_value' => $name['extra']['components'][$key]['options'],
'#required' => TRUE,
'#element_validate' => array(
'_webform_name_options_validate',
),
'#description' => t("Enter one !title per line. Prefix a line using '--' to specify a blank value text. For example: '--Please select a !label'.", array(
'!label' => $label,
)),
);
if (module_exists('taxonomy')) {
// @todo Make the labels more generic.
// Generational suffixes may be also imported from one or more vocabularies
// using the tag '[vocabulary:xxx]', where xxx is the vocabulary id. Terms
// that exceed the maximum length of the generational suffix are not added
// to the options list.
$form['extra']['components'][$key]['options']['#description'] .= ' ' . t("Options may be also imported from one or more vocabularies using the tag '[vocabulary:xxx]', where xxx is the vocabulary machine-name or id. Terms that exceed the maximum length of the component are not added to the options list.");
}
$form['extra']['components'][$key]['sort_options'] = array(
'#type' => 'checkbox',
'#title' => t('Sort options'),
'#default_value' => !empty($name['extra']['components'][$key]['sort_options']),
);
}
}
return $form;
}