You are here

function addressfield_tokens_field_formatter_view in Addressfield Tokens 7

Implements hook_field_formatter_view().

File

./addressfield_tokens.module, line 154
Main components.

Code

function addressfield_tokens_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'addressfield_citystate':
      $theme = array(
        'addressfield_formatter__citystate',
        'addressfield_formatter',
      );
      foreach ($items as $delta => $item) {
        if (!empty($item['country'])) {
          array_unshift($theme, 'addressfield_formatter__citystate__' . $item['country']);
        }
        $element[$delta] = array(
          '#theme' => $theme,
          '#address' => array_map('filter_xss', $item),
        );
      }
      break;
    case 'addressfield_linear':
      $theme = array(
        'addressfield_formatter__linear',
        'addressfield_formatter',
      );
      foreach ($items as $delta => $item) {
        if (!empty($item['country'])) {
          array_unshift($theme, 'addressfield_formatter__linear__' . $item['country']);
        }
        $element[$delta] = array(
          '#theme' => $theme,
          '#address' => array_map('filter_xss', $item),
        );
      }
      break;
    case 'addressfield_country':
      foreach ($items as $delta => $item) {
        if (!empty($item['country'])) {
          $country = _addressfield_tokens_country($item['country']);
          $element[$delta] = array(
            '#type' => 'markup',
            '#markup' => filter_xss($country),
            '#prefix' => '<span class="addressfield-country">',
            '#suffix' => '</span>',
          );
        }
      }
      break;
    case 'addressfield_state':
      foreach ($items as $delta => $item) {
        if (!empty($item['country']) && !empty($item['administrative_area'])) {
          $state = addressfield_tokens_state($item['country'], $item['administrative_area']);
          $element[$delta] = array(
            '#type' => 'markup',
            '#markup' => filter_xss($state),
            '#prefix' => '<span class="addressfield-state">',
            '#suffix' => '</span>',
          );
        }
      }
      break;
    case 'addressfield_components':
      $theme = array(
        'addressfield_formatter__components',
        'addressfield_formatter',
      );
      $settings = $display['settings'];
      foreach ($items as $delta => $item) {
        if (!empty($item['country'])) {
          array_unshift($theme, 'addressfield_formatter__components__' . $item['country']);
        }
        $element[$delta] = array(
          '#theme' => $theme,
          '#address' => array_map('filter_xss', $item),
          '#components' => $settings['components'],
          '#separator' => filter_xss($settings['separator'], array(
            'br',
          )),
        );
      }
      break;
  }
  return $element;
}