You are here

function itoggle_field_field_formatter_view in iToggle 7.2

Same name and namespace in other branches
  1. 7 modules/field/itoggle_field.module \itoggle_field_field_formatter_view()

Implements hook_field_formatter_view().

File

modules/field/itoggle_field.module, line 289
iToggle Field module.

Code

function itoggle_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $elements = array();
  if ($display['type'] === 'itoggle_formatter') {
    $info = entity_get_info($entity_type);
    $bundle_key = $info['bundle keys']['bundle'];
    $id_key = $info['entity keys']['id'];
    $id = $entity->{$id_key};
    $bundle = $entity->{$bundle_key};
    $checked = isset($items[0]['value']) && $items[0]['value'] == 1;
    if ($field['type'] === 'itoggle_field') {
      if ($display['settings']['override'] == 1) {
        $clickable = $display['settings']['clickable'];
        $display_type = $display['settings']['display_type'];
      }
      else {
        $clickable = isset($instance['widget']['settings']['clickable']) ? $instance['widget']['settings']['clickable'] : $display['settings']['clickable'];
        $display_type = isset($instance['widget']['settings']['display_type']) ? $instance['widget']['settings']['display_type'] : $display['settings']['display_type'];
      }
    }
    else {
      $clickable = 0;
      $display_type = $display['settings']['display_type'];
    }
    foreach ($items as $delta => $item) {
      $elements[$delta] = array(
        '#theme' => 'itoggle',
        '#type' => $entity_type,
        '#bundle' => $bundle,
        '#id' => $id,
        '#property' => $field['field_name'],
        '#checked' => $checked,
        '#scope' => 'field',
        '#clickable' => $clickable,
        '#display_type' => $display_type,
      );
    }
  }
  else {
    foreach ($items as $delta => $item) {
      $elements[$delta] = array(
        '#markup' => $item['value'],
      );
    }
  }
  return $elements;
}