You are here

protected function BlazyEntityBase::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.

Overrides BlazyFormatterBase::getEntitiesToView

See also

\Drupal\blazy\BlazyEntityBase

File

src/Plugin/Field/FieldFormatter/BlazyEntityBase.php, line 37

Class

BlazyEntityBase
Base class for entity reference formatters without field details.

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter

Code

protected function getEntitiesToView($items) {
  if (empty($items)) {
    return [];
  }

  // Assumes we have entityreference, or sub-moduled which prepare the view.
  $entities = [];
  foreach ($items as $item) {

    // Skip an item that is not accessible.
    if (empty($item['access'])) {
      continue;
    }
    $entity = clone $item['entity'];
    unset($entity->content);
    $entities[] = $entity;
  }
  return $entities;
}