1 field.api.php | hook_field_formatter_info() |
Expose Field API formatter types.
Formatters handle the display of field values. Formatter hooks are typically called by the Field Attach API field_attach_prepare_view() and field_attach_view() functions.
Return value
An array describing the formatter types implemented by the module.: The keys are formatter type names. To avoid name clashes, formatter type names should be prefixed with the name of the module that exposes them. The values are arrays describing the formatter type, with the following key/value pairs:
- label: The human-readable name of the formatter type.
- description: A short description for the formatter type.
- field types: An array of field types the formatter supports.
- settings: An array whose keys are the names of the settings available for the formatter type, and whose values are the default values for those settings.
See also
hook_field_formatter_info_alter()
hook_field_formatter_prepare_view()
Related topics
File
- core/
modules/ field/ field.api.php, line 1076 - Hooks provided by the Field module.
Code
function hook_field_formatter_info() {
return array(
'text_default' => array(
'label' => t('Default'),
'field types' => array('text', 'text_long', 'text_with_summary'),
),
'text_plain' => array(
'label' => t('Plain text'),
'field types' => array('text', 'text_long', 'text_with_summary'),
),
// The text_trimmed formatter displays the trimmed version of the
// full element of the field. It is intended to be used with text
// and text_long fields. It also works with text_with_summary
// fields though the text_summary_or_trimmed formatter makes more
// sense for that field type.
'text_trimmed' => array(
'label' => t('Trimmed'),
'field types' => array('text', 'text_long', 'text_with_summary'),
),
// The 'summary or trimmed' field formatter for text_with_summary
// fields displays returns the summary element of the field or, if
// the summary is empty, the trimmed version of the full element
// of the field.
'text_summary_or_trimmed' => array(
'label' => t('Summary or trimmed'),
'field types' => array('text_with_summary'),
),
);
}