improvements-2.x-dev/modules/improvements_views/src/Plugin/Field/FieldFormatter/ViewsFormatter.php

modules/improvements_views/src/Plugin/Field/FieldFormatter/ViewsFormatter.php
<?php

namespace Drupal\improvements_views\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\improvements_views\Plugin\Field\FieldType\ViewsItem;

/**
 * @FieldFormatter(
 *   id = "views_formatter",
 *   label = @Translation("Views"),
 *   field_types = {
 *     "views",
 *   },
 * )
 */
class ViewsFormatter extends FormatterBase {

  /**
   * {@inheritDoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode): array {
    $build = [];

    /** @var ViewsItem $item */
    foreach ($items as $delta => $item) {
      [$view_id, $view_display_name] = explode(':', $item->value);
      $build[$delta] = views_embed_view($view_id, $view_display_name);
    }

    return $build;
  }

}

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

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