TableFormatter.php

Contains \Drupal\file\Plugin\field\formatter\TableFormatter.

Namespace

Drupal\file\Plugin\field\formatter

File

drupal/core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php
View source
<?php

/**
 * @file
 * Contains \Drupal\file\Plugin\field\formatter\TableFormatter.
 */
namespace Drupal\file\Plugin\field\formatter;

use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;

/**
 * Plugin implementation of the 'file_table' formatter.
 *
 * @Plugin(
 *   id = "file_table",
 *   module = "file",
 *   label = @Translation("Table of files"),
 *   field_types = {
 *     "file"
 *   }
 * )
 */
class TableFormatter extends FormatterBase {

  /**
   * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
   */
  public function viewElements(EntityInterface $entity, $langcode, array $items) {
    $elements = array();
    if (!empty($items)) {

      // Display all values in a single element.
      $elements[0] = array(
        '#theme' => 'file_formatter_table',
        '#items' => $items,
      );
    }
    return $elements;
  }

}

Classes

Namesort descending Description
TableFormatter Plugin implementation of the 'file_table' formatter.