diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index e4b28a9..9db0d36 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -1075,12 +1075,16 @@ function field_attach_delete_revision($entity_type, $entity) { function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL) { $options = array('langcode' => array()); - // To ensure hooks are only run once per entity, only process items without - // the _field_view_prepared flag. + // To ensure hooks are only run once per entity per view mode, only process + // items without the _field_view_prepared[$view_mode] flag. // @todo: resolve this more generally for both entity and field level hooks. $prepare = array(); foreach ($entities as $id => $entity) { - if (empty($entity->_field_view_prepared)) { + // An entity can be rendered in more than one view mode on given page + // e.g. in preview mode and the display options for a field vary so we need + // to take view mode into account when processing elements and record the + // view mode that the enitity has been built for. + if (empty($entity->_field_view_prepared[$view_mode])) { // Add this entity to the items to be prepared. $prepare[$id] = $entity; @@ -1089,7 +1093,9 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcod $options['langcode'][$id] = field_language($entity_type, $entity, NULL, $langcode); // Mark this item as prepared. - $entity->_field_view_prepared = TRUE; + $entity->_field_view_prepared = array( + $view_mode => TRUE, + ); } }