You are here

protected function BlazyFormatterBase::getEntitiesToView in Blazy 7

Converts $items array to object for easy D8 -> D7 backports.

When extending this class, be sure to override this as needed as $items can be just anything. This one assumes image, or file entity. The actual D8 method is now taken care of at image_field_prepare_view(). At D7, image is not an entity, of course, bear the method name.

See also

\Drupal\blazy\BlazyEntityBase

1 call to BlazyFormatterBase::getEntitiesToView()
BlazyFormatterBlazy::viewElements in src/Plugin/Field/FieldFormatter/BlazyFormatterBlazy.php
Implements hook_field_formatter_view().
1 method overrides BlazyFormatterBase::getEntitiesToView()
BlazyEntityBase::getEntitiesToView in src/Plugin/Field/FieldFormatter/BlazyEntityBase.php
Converts $items array to object for easy D8 -> D7 backports.

File

src/Plugin/Field/FieldFormatter/BlazyFormatterBase.php, line 82

Class

BlazyFormatterBase
Base class for blazy-related modules (slick, etc.).

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter

Code

protected function getEntitiesToView($items) {
  if (empty($items)) {
    return [];
  }
  $files = [];
  foreach ($items as $item) {
    $file = is_object($item) ? $item : (object) $item;
    $file->targetType = 'file';
    $files[] = $file;
  }
  return $files;
}