field_count_formatter.module in Field Count Formatter 7
Same filename and directory in other branches
Simple module to provide a formatter for all field types to show the number of items entered into the field. This is most useful for multiple value fields.
File
field_count_formatter.moduleView source
<?php
/**
* @file
*
* Simple module to provide a formatter for all field types to show the number of items
* entered into the field. This is most useful for multiple value fields.
*/
/**
* Implements hook_field_formatter_info().
*/
function field_count_formatter_field_formatter_info() {
$types = field_info_field_types();
return array(
'count' => array(
'label' => t('Count'),
'field types' => array_keys($types),
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function field_count_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
// ... In case we add another formatter.
if ($display['type'] == 'count') {
$element[0]['#markup'] = count($items);
}
return $element;
}
Functions
Name | Description |
---|---|
field_count_formatter_field_formatter_info | Implements hook_field_formatter_info(). |
field_count_formatter_field_formatter_view | Implements hook_field_formatter_view(). |