class OptionsKeyFormatter

Same name and namespace in other branches
  1. 11.x core/modules/options/src/Plugin/Field/FieldFormatter/OptionsKeyFormatter.php \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
  2. 10 core/modules/options/src/Plugin/Field/FieldFormatter/OptionsKeyFormatter.php \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
  3. 8.9.x core/modules/options/src/Plugin/Field/FieldFormatter/OptionsKeyFormatter.php \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter

Plugin implementation of the 'list_key' formatter.

Plugin annotation


@FieldFormatter(
  id = "list_key",
  label = @Translation("Key"),
  field_types = {
    "list_integer",
    "list_float",
    "list_string",
  }
)

Hierarchy

Expanded class hierarchy of OptionsKeyFormatter

File

core/modules/options/src/Plugin/Field/FieldFormatter/OptionsKeyFormatter.php, line 22

Namespace

Drupal\options\Plugin\Field\FieldFormatter
View source
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;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.