public function ImageLazyLoadController::renderImage in Drupal 9
Render an image using image theme.
Return value
array The render array.
1 string reference to 'ImageLazyLoadController::renderImage'
- image_lazy_load_test.routing.yml in core/
modules/ system/ tests/ modules/ image_lazy_load_test/ image_lazy_load_test.routing.yml - core/modules/system/tests/modules/image_lazy_load_test/image_lazy_load_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ image_lazy_load_test/ src/ Controller/ ImageLazyLoadController.php, line 18
Class
- ImageLazyLoadController
- The ImageLazyLoadController class.
Namespace
Drupal\image_lazy_load_test\ControllerCode
public function renderImage() {
$images['with-dimensions'] = [
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.svg',
'#alt' => 'Image lazy load testing image',
'#prefix' => '<div id="with-dimensions">',
'#suffix' => '</div>',
'#width' => '50%',
'#height' => '50%',
];
$images['without-dimensions'] = [
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.svg',
'#alt' => 'Image lazy load testing image without dimensions',
'#prefix' => '<div id="without-dimensions">',
'#suffix' => '</div>',
];
$images['override-loading-attribute'] = [
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.svg',
'#alt' => 'Image lazy load test loading attribute can be overridden',
'#prefix' => '<div id="override-loading-attribute">',
'#suffix' => '</div>',
'#width' => '50%',
'#height' => '50%',
];
$images['override-loading-attribute']['#attributes']['loading'] = 'eager';
return $images;
}