You are here

function phone_field_formatter_info in Phone 6

Same name and namespace in other branches
  1. 5 phone.module \phone_field_formatter_info()
  2. 7.2 phone.module \phone_field_formatter_info()
  3. 7 phone.module \phone_field_formatter_info()

Implementation of hook_field_formatter_info().

The default behavior of formatters is that they will create a theme for a single field value.

Setting 'multiple values' to CONTENT_HANDLE_FIELD will create a formatter that will receive all the values of a field so you can, for instance, plot all the values on a map or in a graph.

The 'view' operation (handled by the Content module) constructs the $node in a way that you can use drupal_render() to display the formatted output for an individual field.

i.e. print drupal_render($node->field_foo);

The code now supports both single value formatters, which theme an individual item value as has been done in previous version of CCK, and multiple value formatters, which theme all values for the field in a single theme. The multiple value formatters could be used, for instance, to plot field values on a single map or display them in a graph. Single value formatters are the default, multiple value formatters can be designated as such in formatter_info().

The node array will look like:

'Single value' formatter: $node->content['field_foo'] = array( '#type' => 'content_field', '#title' => 'label' '#field_name' => 'field_name', '#node' => $node, 'items' => 0 => array( '#theme' => $theme, '#field_name' => 'field_name', '#type_name' => $node->type, '#formatter' => $formatter_name, '#item' => $items[0], ), 1 => array( '#theme' => $theme, '#field_name' => 'field_name', '#type_name' => $node->type, '#formatter' => $formatter_name, '#item' => $items[1], ), ), ); 'Multiple value' formatter: $node->content['field_foo'] = array( '#type' => 'content_field', '#title' => 'label' '#field_name' => 'field_name', '#node' => $node, 'items' => array( '#theme' => $theme, '#field_name' => 'field_name', '#type_name' => $node->type, '#formatter' => $formatter_name, 0 => array( '#item' => $items[0], ), 1 => array( '#item' => $items[1], ), ), );

File

./phone.module, line 535
Defines phone number fields for CCK. Provide some verifications on the phone numbers

Code

function phone_field_formatter_info() {
  return array(
    'default' => array(
      'label' => 'Default',
      'field types' => array(
        'fr_phone',
        'be_phone',
        'it_phone',
        'el_phone',
        'ch_phone',
        'ca_phone',
        'cr_phone',
        'pa_phone',
        'gb_phone',
        'ru_phone',
        'ua_phone',
        'es_phone',
        'au_phone',
        'cs_phone',
        'hu_phone',
        'pl_phone',
        'nl_phone',
        'se_phone',
        'za_phone',
        'il_phone',
        'nz_phone',
        'br_phone',
        'cl_phone',
        'cn_phone',
        'hk_phone',
        'mo_phone',
        'ph_phone',
        'sg_phone',
        'jo_phone',
        'eg_phone',
        'pk_phone',
        'int_phone',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
  );
}