function _name_field_instance_settings_form in Name Field 7
Implements hook_field_instance_settings_form().
1 call to _name_field_instance_settings_form()
- name_field_instance_settings_form in ./
name.module - Implements hook_field_instance_settings_form().
File
- includes/
name.content.inc, line 285 - Provides additional Field functionality for the name module.
Code
function _name_field_instance_settings_form($field, $instance = NULL) {
$settings = $instance['settings'];
_name_defaults($settings, 'instance_settings');
$components = _name_translations();
$autocomplete_sources = module_invoke_all('name_data_sources');
$form = array(
'size' => array(),
'title_display' => array(),
);
foreach ($components as $key => $title) {
$options = array(
'text' => t('Text field'),
);
$default_field_type = 'text';
foreach ($autocomplete_sources as $ac_source => $ac_settings) {
if (empty($ac_settings['components']) || in_array($key, $ac_settings['components'])) {
if (!empty($ac_settings['list callback'])) {
$options['select'] = t('Drop-down');
$default_field_type = 'select';
}
if (!empty($ac_settings['autocomplete callback'])) {
$options['autocomplete'] = t('Autocomplete');
}
}
}
$form['field_type'][$key] = array(
'#type' => 'radios',
'#title' => t('!title field type', array(
'!title' => $components['title'],
)),
// Provides backwards compatibility with Drupal 6 modules.
'#default_value' => isset($settings['field_type'][$key]) ? $settings['field_type'][$key] : (isset($settings[$key . '_field']) ? $settings[$key . '_field'] : $default_field_type),
'#required' => TRUE,
'#options' => $options,
);
$form['size'][$key] = array(
'#type' => 'textfield',
'#title' => t('HTML size property for !title', array(
'!title' => $title,
)),
'#default_value' => isset($settings['size']) ? $settings['size'][$key] : '',
'#required' => FALSE,
'#size' => 10,
'#description' => t('The maximum length of the field in characters. This must be between 1 and 255.'),
'#element_validate' => array(
'_element_validate_integer_positive',
),
);
$form['title_display'][$key] = array(
'#type' => 'radios',
'#title' => t('Label display for !title', array(
'!title' => $title,
)),
'#default_value' => isset($settings['title_display']) ? $settings['title_display'][$key] : 'description',
'#options' => array(
'title' => t('above'),
'description' => t('below'),
'placeholder' => t('placeholder'),
'none' => t('hidden'),
),
'#description' => t('This controls how the label of the component is displayed in the form.'),
);
$form['inline_css'][$key] = array(
'#type' => 'textfield',
'#title' => t('Additional inline styles for !title input element.', array(
'!title' => $title,
)),
'#default_value' => isset($settings['inline_css']) ? $settings['inline_css'][$key] : '',
'#size' => 8,
);
$form['labels'][$key] = array(
'#type' => 'textfield',
'#title' => t('Label for !title', array(
'!title' => $title,
)),
'#default_value' => isset($settings['labels']) ? $settings['labels'][$key] : '',
'#size' => 12,
);
}
$form['components'] = array(
'#type' => 'checkboxes',
'#title' => t('Components overrides'),
'#default_value' => $settings['components'],
'#options' => $components,
'#element_validate' => array(
'_name_field_minimal_component_requirements',
),
);
$form['minimum_components'] = array(
'#type' => 'checkboxes',
'#title' => t('Minimum components overrides'),
'#default_value' => $settings['minimum_components'],
'#element_validate' => array(
'_name_field_minimal_component_requirements',
),
'#options' => $components,
);
$form['component_css'] = array(
'#type' => 'textfield',
'#title' => t('Component separator CSS'),
'#default_value' => empty($settings['component_css']) ? '' : $settings['component_css'],
'#description' => t('Use this to override the default CSS used when rendering each component. Use "<none>" to prevent the use of inline CSS.'),
);
$items = array(
t('The order for Asian names is Family Middle Given Title'),
t('The order for Eastern names is Title Family Given Middle'),
t('The order for Western names is Title First Middle Surname'),
);
$layout_description = t('<p>This controls the order of the widgets that are displayed in the form.</p>') . theme('item_list', array(
'items' => $items,
)) . t('<p>Note that when you select the Asian names format, the Generational field is hidden and defaults to an empty string.</p>');
$form['component_layout'] = array(
'#type' => 'radios',
'#title' => t('Language layout'),
'#default_value' => isset($settings['component_layout']) ? $settings['component_layout'] : 'default',
'#options' => array(
'default' => t('Western names'),
'asian' => t('Asian names'),
'eastern' => t('Eastern names'),
),
'#description' => $layout_description,
);
$form['show_component_required_marker'] = array(
'#type' => 'checkbox',
'#title' => t('Show component required marker'),
'#default_value' => empty($settings['show_component_required_marker']) ? 0 : 1,
'#description' => t('Appends an asterisk after the component title if the component is required as part of a complete name.'),
);
$form['credentials_inline'] = array(
'#type' => 'checkbox',
'#title' => t('Show the credentials inline'),
'#default_value' => empty($settings['credentials_inline']) ? 0 : 1,
'#description' => t('The default position is to show the credentials on a line by themselves. This option overrides this to render the component inline.'),
);
// Add the overwrite user name option.
if ($instance['entity_type'] == 'user' && $instance['bundle'] == 'user') {
$preferred_field = variable_get('name_user_preferred', '');
$form['name_user_preferred'] = array(
'#type' => 'checkbox',
'#title' => t('Use this field to override the users login name?'),
'#default_value' => $preferred_field == $instance['field_name'] ? 1 : 0,
);
$form['override_format'] = array(
'#type' => 'select',
'#title' => t('User name override format to use'),
'#default_value' => isset($settings['override_format']) ? $settings['override_format'] : 'default',
'#options' => array(
'default' => t('Default'),
) + name_get_custom_format_options(),
);
}
else {
// We may extend this feature to Profile2 latter.
$form['override_format'] = array(
'#type' => 'value',
'#value' => isset($settings['override_format']) ? $settings['override_format'] : 'default',
);
}
$form['preferred_field_reference'] = array(
'#type' => 'select',
'#title' => t('Preferred component source'),
'#empty_option' => t('-- none --'),
'#options' => name_get_additional_sources($instance),
'#default_value' => empty($settings['preferred_field_reference']) ? '' : $settings['preferred_field_reference'],
'#description' => t('A data source to use as the preferred given name within the name formats. A common use-case would be for a users nickname.') . '<br>' . t('i.e. used in the name format options "q" and "v", plus the conditional "p", "x", "d" and "D".'),
);
return $form;
}