You are here

function styles_field_formatter_view in Styles 7

Same name and namespace in other branches
  1. 7.2 styles.module \styles_field_formatter_view()

Implements hook_field_formatter_view().

File

./styles.module, line 57
Bundles similar display formatters together.

Code

function styles_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array(
    '#formatter' => $display['type'],
  );
  foreach ($items as $delta => $item) {

    // @todo This should be refactored, but for legacy reasons, we pass a
    //   context object containing both the field item keys and the entity
    //   properties, because there are current use-cases of each one being
    //   needed. For example, file_styles_styles_formatter_filter() expects
    //   $object to contain a file field's $item data, and
    //   theme_media_youtube_embed() expects $object to contain the entity's
    //   'override' property. This came about because an early use-case of the
    //   Styles module is the Media module, where there is tight coupling
    //   between the entity and the field item. Creating a merged context object
    //   is an initial step towards making the Styles module usable by modules
    //   other than Media. See http://drupal.org/node/797502.
    $object = (object) ((array) $item + (array) $entity);
    $element[$delta] = array(
      '#markup' => theme('styles_field_formatter', array(
        'element' => $element,
        'object' => $object,
      )),
    );
  }
  return $element;
}