public function Loader::loadEntity in Bamboo Twig 8
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_loaders/
src/ TwigExtension/ Loader.php, line 122
Class
- Loader
- Provides a 'Loader' Twig Extensions.
Namespace
Drupal\bamboo_twig_loaders\TwigExtensionCode
public function loadEntity($entity_type, $id = NULL, $view_mode = NULL, $langcode = NULL) {
$entity = $id ? $this->entityTypeManager
->getStorage($entity_type)
->load($id) : $this->routeMatch
->getParameter($entity_type);
if ($entity) {
$render_controller = $this->entityTypeManager
->getViewBuilder($entity_type);
return $render_controller
->view($entity, $view_mode, $langcode);
}
return NULL;
}