You are here

GridstackFormatter.php in DXPR GridStack 8

Same filename and directory in other branches
  1. 1.0.x src/Plugin/Field/FieldFormatter/GridstackFormatter.php

File

src/Plugin/Field/FieldFormatter/GridstackFormatter.php
View source
<?php

namespace Drupal\dxpr_gridstack\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;

/**
 * Plugin implementation of the 'Gridstack' formatter.
 *
 * @FieldFormatter(
 *   id = "dxpr_gridstack_gridstack",
 *   label = @Translation("Gridstack"),
 *   field_types = {
 *     "image"
 *   }
 * )
 */
class GridstackFormatter extends ImageFormatter {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = parent::viewElements($items, $langcode);
    foreach ($elements as $delta => $element) {
      $elements[$delta]['#theme'] = 'dxpr_gridstack_gridstack_formatter';
    }
    return $elements;
  }

}

Classes

Namesort descending Description
GridstackFormatter Plugin implementation of the 'Gridstack' formatter.