Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Summary
In Drupal 7, render arrays generated by field formatters contained the field values as a plain array in $element['#items'] (received by theme_field() and hook_preprocess_field() as $variables['items']).

In Drupal 8, the $element['#items'] / $variables['items'] placed by FormatterBase::view() is the same data structure that is used throughout all the Entity / Field API runtime code : a FieldItemListInterafce object.
- That object implements ArrayAccess, and can thus be treated as an array of Item objects keyed by numeric delta.
- Values are accessed using the $items[$delta]->property syntax instead of $items[$delta]['property'].

The following hooks are impacted:

No syntax change is needed inside Twig templates, as the Twig syntax already handles the object/array syntax variants.

Additionally, formatters that delegate the rendering of each individual item to dedicated theme functions typically passed $element['#item] / $variables['item'] as an array. Similarly, they should preferably be updated to directly pass the FieldItemInterface objects.

The following core theme functions, used by image formatters, have been updated that way:

  • theme_image_formatter()
  • theme_picture_formatter()
Impacts: 
Module developers
Themers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done