public function BlazyEntityBase::buildElements in Blazy 8
Same name and namespace in other branches
- 8.2 src/Dejavu/BlazyEntityBase.php \Drupal\blazy\Dejavu\BlazyEntityBase::buildElements()
Returns media contents.
1 call to BlazyEntityBase::buildElements()
- BlazyTestEntityReferenceFormatterTest::viewElements in tests/
modules/ blazy_test/ src/ Plugin/ Field/ FieldFormatter/ BlazyTestEntityReferenceFormatterTest.php - Builds a renderable array for a field value.
File
- src/
Dejavu/ BlazyEntityBase.php, line 16
Class
- BlazyEntityBase
- Base class for entity reference formatters without field details.
Namespace
Drupal\blazy\DejavuCode
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;
if ($entity
->id()) {
$this
->buildElement($build, $entity, $langcode);
// Add the entity to cache dependencies so to clear when it is updated.
$this
->manager()
->getRenderer()
->addCacheableDependency($build['items'][$delta], $entity);
}
else {
$this->referencedEntities = NULL;
// This is an "auto_create" item.
$build['items'][$delta] = [
'#markup' => $entity
->label(),
];
}
$depth = 0;
}
// Supports Blazy formatter multi-breakpoint images if available.
if (empty($build['settings']['vanilla'])) {
$this
->formatter()
->isBlazy($build['settings'], $build['items'][0]);
}
}