You are here

function field_extract_formatted in Field Extract Values 7

Finds and invokes the required formatter for the field

1 call to field_extract_formatted()
field_extract_values in ./field_extract.module
Fetch values of an entity's field

File

./field_extract.module, line 209
Field extract - Extension of the Field API to allow proper extraction of field values from entities

Code

function field_extract_formatted($options) {
  extract($options);
  $parent_entity_id = $parent_entity->{$parent_entity_info['entity keys']['id']};
  $langcode = isset($langcode) ? $langcode : $parent_entity->language;
  $delta_flag = FALSE;
  $items = field_get_items($parent_entity_type, $parent_entity, $field_name);
  if (isset($items[$delta])) {
    $items = array(
      $items[$delta],
    );
    $delta_flag = TRUE;
  }
  $display = array(
    'type' => isset($formatter) ? $formatter : 'default',
  );

  // Prepare the field items for display
  $itemz = array(
    $parent_entity_id => &$items,
  );
  $args = array(
    $parent_entity_type,
    array(
      $parent_entity_id => $parent_entity,
    ),
    $field_info,
    array(
      $parent_entity_id => $instance_info,
    ),
    $langcode,
    &$itemz,
  );
  $function = "{$field_type_info['module']}_field_prepare_view";
  if (function_exists($function)) {
    call_user_func_array($function, $args);
  }
  $results = module_invoke($field_type_info['module'], 'field_formatter_view', $parent_entity_type, $parent_entity, $field_info, $instance_info, $langcode, $items, $display);
  if ($delta_flag) {
    $results = array_pop($results);
  }
  return $results;
}