You are here

public function Render::renderImage in Bamboo Twig 8.4

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.2 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderImage()
  3. 8.3 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 119

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;
}