class FieldFormatter

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Annotation/FieldFormatter.php \Drupal\Core\Field\Annotation\FieldFormatter
  2. 8.9.x core/lib/Drupal/Core/Field/Annotation/FieldFormatter.php \Drupal\Core\Field\Annotation\FieldFormatter
  3. 11.x core/lib/Drupal/Core/Field/Attribute/FieldFormatter.php \Drupal\Core\Field\Attribute\FieldFormatter
  4. 11.x core/lib/Drupal/Core/Field/Annotation/FieldFormatter.php \Drupal\Core\Field\Annotation\FieldFormatter

Defines a FieldFormatter attribute for plugin discovery.

Formatters handle the display of field values. They are typically instantiated and invoked by an EntityDisplay object.

Additional attribute keys for formatters can be defined in hook_field_formatter_info_alter().

Attributes

#[\Attribute(\Attribute::TARGET_CLASS)]

Hierarchy

  • class \Drupal\Core\Field\Attribute\FieldFormatter extends \Drupal\Component\Plugin\Attribute\Plugin

Expanded class hierarchy of FieldFormatter

See also

\Drupal\Core\Field\FormatterPluginManager

\Drupal\Core\Field\FormatterInterface

Related topics

66 files declare their use of FieldFormatter
AttachmentTestFormatter.php in core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
AuthorFormatter.php in core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php
AuthorNameFormatter.php in core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php
BasicStringFormatter.php in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BasicStringFormatter.php
BooleanFormatter.php in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php

... See full list

File

core/lib/Drupal/Core/Field/Attribute/FieldFormatter.php, line 24

Namespace

Drupal\Core\Field\Attribute
View source
class FieldFormatter extends Plugin {
    
    /**
     * Constructs a FieldFormatter attribute.
     *
     * @param string $id
     *   The plugin ID.
     * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
     *   (optional) The human-readable name of the formatter type.
     * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
     *   (optional) A short description of the formatter type.
     * @param string[] $field_types
     *   (optional) An array of field types the formatter supports.
     * @param int|null $weight
     *   (optional) An integer to determine the weight of this formatter.
     *   Weight is relative to other formatters in the Field UI when selecting a
     *   formatter for a given field instance.
     * @param class-string|null $deriver
     *   (optional) The deriver class.
     */
    public function __construct(string $id, ?TranslatableMarkup $label = NULL, ?TranslatableMarkup $description = NULL, array $field_types = [], ?int $weight = NULL, ?string $deriver = NULL) {
    }

}

Members

Title Sort descending Modifiers Object type Summary
FieldFormatter::__construct public function Constructs a FieldFormatter attribute.

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