page_layouts-1.0.1/src/Plugin/Layouts/FullWidthSingleImage.php
src/Plugin/Layouts/FullWidthSingleImage.php
<?php
declare(strict_types=1);
namespace Drupal\page_layouts\Plugin\Layouts;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\file\Entity\File;
use Drupal\page_layouts\LayoutsPluginBase;
/**
* Plugin implementation of the layouts.
*
* @Layouts(
* id = "layouts_full_width_single_image",
* label = @Translation("Full Width Single Image"),
* description = @Translation("Full width single image.")
* )
*/
final class FullWidthSingleImage extends LayoutsPluginBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getLayout($result) {
$file = File::load($result->image_1->target_id);
$image['preview'] = [
'#theme' => 'image_style',
'#style_name' => 'large',
'#uri' => $file->uri->value,
'#alt' => $result->image_1->alt,
];
$build['layout'] = [
'#theme' => 'layouts_full_width_single_image',
'#content' => [
'image_1' => $image,
],
];
return \Drupal::service('renderer')->render($build);
}
}
