You are here

function classified_field_formatter_view in Classified Ads 7.3

Implements hook_field_formatter_view().

An ad may appear in multiple categories. Link will to Classified Ads pages only for terms in the Classified Ads vocabulary, and normal taxonomy pages otherwise.

We do not test the formatter type since we only defined one.

File

./classified.module, line 1001
A pure D7 classified ads module inspired by the ed_classified module.

Code

function classified_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $ret = array();
  $vid = _classified_get('vid');
  $term_ids = array();
  foreach ($items as $item) {
    $term_ids[] = $item['tid'];
  }
  $terms = taxonomy_term_load_multiple($term_ids);
  foreach ($items as $delta => $item) {
    $tid = $item['tid'];
    if ($display['settings']['link_title']) {
      $title = $terms[$tid]->vid == $vid ? t('Classified Ads in the @title category', array(
        '@title' => $terms[$tid]->name,
      )) : t('Content flagged with @title', array(
        '@title' => $terms[$tid]->name,
      ));
      $attributes = array(
        'title' => $title,
      );
    }
    else {
      $attributes = array();
    }
    $ret[$delta] = array(
      '#markup' => l($terms[$tid]->name, classified_term_path($terms[$tid]), array(
        'attributes' => $attributes,
      )),
    );
  }
  return $ret;
}