You are here

function fasttoggle_field_field_formatter_view in Fasttoggle 7

Implements hook_field_formatter_view().

File

module/fasttoggle_field/fasttoggle_field.module, line 171

Code

function fasttoggle_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'fasttoggle':
      switch ($entity_type) {
        case 'node':
          $id = $entity->nid;
          break;
        case 'user':
          $id = $entity->uid;
          break;
        default:
          return $element;
      }
      $options = fasttoggle_get_allowed_links($entity_type, $entity, $id, 'fasttoggle_add_to_node_links');
      if (!empty($options) && isset($options['fields'][$entity->type]['instances'][$field['field_name']])) {
        $label_style = variable_get('fasttoggle_label_style', FASTTOGGLE_LABEL_STATUS);
        $element[] = fasttoggle($options, $entity->type, $field['field_name'], $entity, FASTTOGGLE_FORMAT_FORM);
      }
      else {

        // Invoke the default formatter instead
        // Based on prepareInstanceDisplay in field.info.class.inc.
        $field_type_info = field_info_field_types($field['type']);
        $display['type'] = $field_type_info['default_formatter'];
        $formatter_type_info = field_info_formatter_types($display['type']);
        $display['module'] = $formatter_type_info['module'];

        // Fill in default settings for the formatter.
        $display['settings'] = field_info_formatter_settings($display['type']);
        $temp = field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
        if ($temp) {
          $temp = array_shift($temp);
          $temp['#label_display'] = "hidden";
          $element[] = $temp;
        }
      }
      break;
  }
  return $element;
}