function name_field_formatter_settings_form in Name Field 7
Implements hook_field_formatter_settings_form().
File
- ./
name.module, line 1246 - Defines an API for displaying and inputing names.
Code
function name_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element['format'] = array(
'#type' => 'select',
'#title' => t('Name format'),
'#default_value' => isset($settings['format']) ? $settings['format'] : 'default',
'#options' => array(
'default' => t('Default'),
) + name_get_custom_format_options(),
'#required' => TRUE,
);
$element['markup'] = array(
'#type' => 'checkbox',
'#title' => t('Markup'),
'#default_value' => !empty($settings['markup']),
'#description' => t('This option wraps the individual components of the name in SPAN elements with corresponding classes to the component.'),
);
$element['output'] = array(
'#type' => 'radios',
'#title' => t('Output'),
'#default_value' => empty($settings['output']) ? 'default' : $settings['output'],
'#options' => _name_formatter_output_options(),
'#description' => t('This option provides additional options for rendering the field. <strong>Normally, using the "Raw value" option would be a security risk.</strong>'),
'#required' => TRUE,
);
$element['multiple'] = array(
'#type' => 'radios',
'#title' => t('Multiple format options'),
'#default_value' => empty($settings['multiple']) ? 'default' : $settings['multiple'],
'#options' => _name_formatter_multiple_options(),
'#required' => TRUE,
);
$settings += array(
'multiple_delimiter' => ', ',
// And or symbol.
'multiple_and' => 'text',
// contextual, always, never.
'multiple_delimiter_precedes_last' => 'never',
'multiple_el_al_min' => 3,
'multiple_el_al_first' => 1,
);
$base = array(
'#states' => array(
'visible' => array(
':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][multiple]"]' => array(
'value' => 'inline_list',
),
),
),
'#prefix' => '<div style="padding: 0 2em;">',
'#suffix' => '</div>',
);
// We can not nest this field, so use a prefix / suffix with padding to help
// to provide context.
$element['multiple_delimiter'] = $base + array(
'#type' => 'textfield',
'#title' => t('Delimiter'),
'#default_value' => $settings['multiple_delimiter'],
'#description' => t('This specifies the delimiter between the second to last and the last name.'),
);
$element['multiple_and'] = $base + array(
'#type' => 'radios',
'#title' => t('Last delimiter type'),
'#options' => array(
'text' => t('Textual (and)'),
'symbol' => t('Ampersand (&)'),
'inherit' => t('Inherit'),
),
'#default_value' => $settings['multiple_and'],
'#description' => t('This specifies the delimiter between the second to last and the last name.'),
);
$element['multiple_delimiter_precedes_last'] = $base + array(
'#type' => 'radios',
'#title' => t('Standard delimiter precedes last delimiter'),
'#options' => array(
'never' => t('Never (i.e. "J. Doe and T. Williams")'),
'always' => t('Always (i.e. "J. Doe<strong>,</strong> and T. Williams")'),
'contextual' => t('Contextual (i.e. "J. Doe and T. Williams" <em>or</em> "J. Doe, S. Smith<strong>,</strong> and T. Williams")'),
),
'#default_value' => $settings['multiple_delimiter_precedes_last'],
'#description' => t('This specifies the delimiter between the second to last and the last name. Contextual means that the delimiter is only included for lists with three or more names.'),
);
$element['multiple_el_al_min'] = $base + array(
'#type' => 'select',
'#title' => t('Reduce list and append <em>el al</em>'),
'#options' => array(
0 => t('Never reduce'),
) + drupal_map_assoc(range(1, 20)),
'#default_value' => $settings['multiple_el_al_min'],
'#description' => t('This specifies a limit on the number of names to display. After this limit, names are removed and the abbrivation <em>et al</em> is appended. This Latin abbrivation of <em>et alii</em> means "and others".'),
);
$element['multiple_el_al_first'] = $base + array(
'#type' => 'select',
'#title' => t('Number of names to display when using <em>el al</em>'),
'#options' => drupal_map_assoc(range(1, 20)),
'#default_value' => $settings['multiple_el_al_first'],
);
return $element;
}