You are here

function text_field_formatter_info in Content Construction Kit (CCK) 6

Same name in this branch
  1. 6 examples/simple_field.php \text_field_formatter_info()
  2. 6 examples/example_field.php \text_field_formatter_info()
  3. 6 modules/text/text.module \text_field_formatter_info()
Same name and namespace in other branches
  1. 5 text.module \text_field_formatter_info()
  2. 6.3 modules/text/text.module \text_field_formatter_info()
  3. 6.2 modules/text/text.module \text_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_view', '#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_view', '#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

examples/simple_field.php, line 323
SIMPLE EXAMPLE. This is similar to to example_field but creates only a single widget formatted in the traditional manner, not using hook_elements. This example also omits all optional parts of the field module to create a simpler example for…

Code

function text_field_formatter_info() {
  return array(
    'default' => array(
      'label' => t('Default'),
      'field types' => array(
        'text',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
    'plain' => array(
      'label' => t('Plain text'),
      'field types' => array(
        'text',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
  );
}