page_layouts-1.0.1/src/Plugin/Layouts/ImageLeftImageRight.php
src/Plugin/Layouts/ImageLeftImageRight.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_image_left_image_right",
* label = @Translation("Image Left Image Right"),
* description = @Translation("Image on the left image on the right each taking up half the space.")
* )
*/
final class ImageLeftImageRight extends LayoutsPluginBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getLayout($result) {
$file = File::load($result->image_1->target_id);
// Create configuration to change image_style.
$image_1['preview'] = [
'#theme' => 'image_style',
'#style_name' => 'large',
'#uri' => $file->uri->value,
'#alt' => $result->image_1->alt,
];
$file_2 = File::load($result->image_2->target_id);
// Create configuration to change image_style.
$image_2['preview_2'] = [
'#theme' => 'image_style',
'#style_name' => 'large',
'#uri' => $file_2->uri->value,
'#alt' => $result->image_2->alt,
];
$build['layout'] = [
'#theme' => 'layouts_image_left_image_right',
'#content' => [
'image_1' => $image_1,
'image_2' => $image_2,
],
];
return \Drupal::service('renderer')->render($build);
}
}
