You are here

public function Loader::loadEntity in Bamboo Twig 8.3

Same name and namespace in other branches
  1. 8.5 bamboo_twig_loader/src/TwigExtension/Loader.php \Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity()
  2. 8.2 bamboo_twig_loader/src/TwigExtension/Loader.php \Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity()
  3. 8.4 bamboo_twig_loader/src/TwigExtension/Loader.php \Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity()

Returns an entity object.

Parameters

string $entity_type: The entity type.

mixed $id: (optional) The ID of the entity to load.

Return value

null|Drupal\Core\Entity\EntityInterface An entity object for the entity or NULL if the entity does not exist.

1 call to Loader::loadEntity()
Loader::loadField in bamboo_twig_loader/src/TwigExtension/Loader.php
Returns the field object for a single entity field.

File

bamboo_twig_loader/src/TwigExtension/Loader.php, line 42

Class

Loader
Provides some loaders as Twig Extensions.

Namespace

Drupal\bamboo_twig_loader\TwigExtension

Code

public function loadEntity($entity_type, $id = NULL) {
  $entity = $id ? $this
    ->getEntityTypeManager()
    ->getStorage($entity_type)
    ->load($id) : $this
    ->getCurrentRouteMatch()
    ->getParameter($entity_type);
  if (!$entity) {
    return NULL;
  }
  return $entity;
}