Index: styles.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/styles/styles.module,v
retrieving revision 1.2.2.26
diff -u -p -r1.2.2.26 styles.module
--- styles.module	25 Jan 2010 22:18:34 -0000	1.2.2.26
+++ styles.module	28 Sep 2010 23:33:11 -0000
@@ -55,15 +55,23 @@ function styles_field_formatter_info() {
 /**
  *  Implements hook_field_formatter_view().
  */
-function styles_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {
+function styles_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
   $element = array('#formatter' => $display['type']);
-  if (!is_array($object)) {
-    $object = array($object);
+  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)));
   }
-  foreach ($object as $delta => $item) {
-    $element[$delta] = array('#markup' => theme('styles_field_formatter', array('element' => $element, 'object' => $item)));
-  }
-
   return $element;
 }
 
