gmap_cck_field_formatter

Definition

gmap_cck_field_formatter($field, $item, $formatter, $node)
gmap_addons/gmap_cck.module, line 265

Description

Prepare an individual item for viewing in a browser.

In a multiple-value field scenario, this function will be called once per value currently stored in the field. This function is also used as the handler for viewing a field in a views.module tabular listing.

It is important that this function at the minimum perform security transformations such as running check_plain() or check_markup().

Parameters

$field The field the action is being performed on.

$item An array, keyed by column, of the data stored for this item in this field.

$formatter The name of the formatter being used to display the field.

$node The node object, for context. Will be NULL in some cases. Warning : when displaying field retrieved by Views, $node will not be a "full-fledged" node object, but an object containg the data returned by the Views query (at least nid, vid, changed)

Return value

An HTML string containing the formatted item.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function gmap_cck_field_formatter($field, $item, $formatter, $node) {
  if (!isset($item['value'])) {
    return '';
  }

  $m = unserialize($item['value']);
  if (!is_array($m)) $m = array();
  if (!empty($field['gpx']) && _gmap_cck_check_gpx_source($m, $field, $node)) {
    _gmap_cck_get_gpx($m, $field, $node);
  }
  if (!empty($field['marker_noderef'])) {
    _gmap_cck_noderef_markers($m, $field, $node);
  }
  $map = array_merge(gmap_defaults(), $field, $m);

  $map['id'] = 'gmap';
  if (isset($node) && isset($node->nid)) $map['id'] .= '_'. $node->nid;
  $map['id'] .= '_'. $field['field_name'];

  // TODO: correct width, height & zoom if ($formatter != 'default')

  return theme('gmap', array('#settings' => $map));
}
?>