// Protect ourselves from recursive rendering: return an empty render array.
if (static::
$recursiveRenderDepth[$recursive_render_id] > EntityReferenceEntityFormatter::RECURSIVE_RENDER_LIMIT
) { $this->loggerFactory->
get('media'
)->
error('During rendering of embedded media: recursive rendering detected for %entity_id. Aborting rendering.',
[ '%entity_id' =>
$media->
id(),
]);
return [];
} $build =
$this->entityTypeManager
->
getViewBuilder('media'
) ->
view($media,
$view_mode,
$langcode);
// Allows other modules to treat embedded media items differently.
$build['#embed'
] = TRUE;
// There are a few concerns when rendering an embedded media entity:
// - entity access checking happens not during rendering but during routing,
// and therefore we have to do it explicitly here for the embedded entity.
$build['#access'
] =
$media->
access('view', NULL, TRUE
);
// - caching an embedded media entity separately is unnecessary; the host
// entity is already render cached.
unset($build['#cache'
]['keys'
]);