Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

OptionsKeyFormatter.php

Namespace

Drupal\options\Plugin\Field\FieldFormatter

File

core/modules/options/src/Plugin/Field/FieldFormatter/OptionsKeyFormatter.php

View source
<?php

namespace Drupal\options\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Plugin implementation of the 'list_key' formatter.
 */
class OptionsKeyFormatter extends FormatterBase {
    
    /**
     * {@inheritdoc}
     */
    public function viewElements(FieldItemListInterface $items, $langcode) {
        $elements = [];
        foreach ($items as $delta => $item) {
            $elements[$delta] = [
                '#markup' => $item->value,
                '#allowed_tags' => FieldFilteredMarkup::allowedTags(),
            ];
        }
        return $elements;
    }

}

Classes

Title Deprecated Summary
OptionsKeyFormatter Plugin implementation of the 'list_key' formatter.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal