pm-4.1.x-dev/src/Plugin/Field/FieldFormatter/PmuiPillsFormatter.php

src/Plugin/Field/FieldFormatter/PmuiPillsFormatter.php
<?php

namespace Drupal\pm\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;

/**
 * Plugin implementation of the 'PmUi Pills' formatter.
 *
 * @FieldFormatter(
 *   id = "pm_pmui_pills",
 *   label = @Translation("PmUi Pills"),
 *   field_types = {
 *     "entity_reference"
 *   }
 * )
 */
class PmuiPillsFormatter extends EntityReferenceFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $element = [];
    /** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items */
    /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
    $entities = $this->getEntitiesToView($items, $langcode);
    foreach ($entities as $delta => $entity) {
      $element[$delta] = [
        '#type' => 'component',
        '#component' => 'pm_ui:pill',
        '#props' => [
          'color' => $entity->get('color')->value,
          'label' => $entity->label(),
        ],
      ];
    }
    return $element;
  }

}

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

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