page_layouts-1.0.1/src/Plugin/Layouts/ImageLeftTextRight.php

src/Plugin/Layouts/ImageLeftTextRight.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_text_right",
 *   label = @Translation("Image Left Text Right"),
 *   description = @Translation("Image on the left text on the right each taking up half the space.")
 * )
 */
final class ImageLeftTextRight 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,
    ];

    $build['layout'] = [
      '#theme' => 'layouts_image_left_text_right',
      '#content' => [
        'image_1' => $image_1,
        'content_1' => $result->content_1->value,
      ],
    ];

    return \Drupal::service('renderer')->render($build);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc