You are here

public function BlazyEntityBase::buildElements in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/Dejavu/BlazyEntityBase.php \Drupal\blazy\Dejavu\BlazyEntityBase::buildElements()

Returns media contents.

1 call to BlazyEntityBase::buildElements()
BlazyEntityMediaBase::buildElements in src/Dejavu/BlazyEntityMediaBase.php
Returns media contents.
1 method overrides BlazyEntityBase::buildElements()
BlazyEntityMediaBase::buildElements in src/Dejavu/BlazyEntityMediaBase.php
Returns media contents.

File

src/Dejavu/BlazyEntityBase.php, line 18

Class

BlazyEntityBase
Base class for entity reference formatters without field details.

Namespace

Drupal\blazy\Dejavu

Code

public function buildElements(array &$build, $entities, $langcode) {
  foreach ($entities as $delta => $entity) {

    // Protect ourselves from recursive rendering.
    static $depth = 0;
    $depth++;
    if ($depth > 20) {
      $this->loggerFactory
        ->get('entity')
        ->error('Recursive rendering detected when rendering entity @entity_type @entity_id. Aborting rendering.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '@entity_id' => $entity
          ->id(),
      ]);
      return $build;
    }
    $build['settings']['delta'] = $delta;
    $build['settings']['langcode'] = $langcode;
    $this
      ->buildElement($build, $entity, $langcode);

    // Add the entity to cache dependencies so to clear when it is updated.
    $this
      ->formatter()
      ->getRenderer()
      ->addCacheableDependency($build['items'][$delta], $entity);
    $depth = 0;
  }
}