You are here

public function Render::renderImage in Bamboo Twig 8.2

Same name and namespace in other branches
  1. 8.5 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderImage()
  2. 8.3 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderImage()
  3. 8.4 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderImage()

Returns the render array for an image style.

Parameters

int $id: The image File ID of the entity to render.

string $style: The image style.

Return value

string A render array for the image style or NULL if the image does not exist.

File

bamboo_twig_loader/src/TwigExtension/Render.php, line 112

Class

Render
Provides some renderer as Twig Extensions.

Namespace

Drupal\bamboo_twig_loader\TwigExtension

Code

public function renderImage($id, $style) {
  $file = $this
    ->getFileStorage()
    ->load($id);

  // Check the entity exist.
  if ($file) {
    return [
      '#theme' => 'image_style',
      '#style_name' => $style,
      '#uri' => $file
        ->getFileUri(),
    ];
  }
  return NULL;
}