public function Render::renderEntity in Bamboo Twig 8.3
Same name and namespace in other branches
- 8.5 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderEntity()
- 8.2 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderEntity()
- 8.4 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderEntity()
Returns the render array for an entity.
Parameters
string $entity_type: The entity type.
mixed $id: (optional) The ID of the entity to render.
string $view_mode: (optional) The view mode that should be used to render the entity.
string $langcode: (optional) For which language the entity should be rendered, defaults to the current content language.
Return value
null|array A render array for the entity or NULL if the entity does not exist.
File
- bamboo_twig_loader/
src/ TwigExtension/ Render.php, line 87
Class
- Render
- Provides some renderer as Twig Extensions.
Namespace
Drupal\bamboo_twig_loader\TwigExtensionCode
public function renderEntity($entity_type, $id = NULL, $view_mode = NULL, $langcode = NULL) {
// Lazy load the entity type manager only when needed.
$entityTypeManager = $this
->getEntityTypeManager();
$entity = $id ? $entityTypeManager
->getStorage($entity_type)
->load($id) : $this
->getCurrentRouteMatch()
->getParameter($entity_type);
if ($entity) {
$render_controller = $entityTypeManager
->getViewBuilder($entity_type);
return $render_controller
->view($entity, $view_mode, $langcode);
}
return NULL;
}