interface FormatterInterface

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/FormatterInterface.php \Drupal\Core\Field\FormatterInterface
  2. 10 core/lib/Drupal/Core/Field/FormatterInterface.php \Drupal\Core\Field\FormatterInterface
  3. 11.x core/lib/Drupal/Core/Field/FormatterInterface.php \Drupal\Core\Field\FormatterInterface

Interface definition for field formatter plugins.

Hierarchy

Expanded class hierarchy of FormatterInterface

All classes that implement FormatterInterface

Related topics

2 files declare their use of FormatterInterface
FieldBlock.php in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
field_third_party_test.module in core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module
Test module.

File

core/lib/Drupal/Core/Field/FormatterInterface.php, line 12

Namespace

Drupal\Core\Field
View source
interface FormatterInterface extends PluginSettingsInterface {
    
    /**
     * Returns a form to configure settings for the formatter.
     *
     * Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow
     * administrators to configure the formatter. The field_ui module takes care
     * of handling submitted form values.
     *
     * @param array $form
     *   The form where the settings form is being included in.
     * @param \Drupal\Core\Form\FormStateInterface $form_state
     *   The current state of the form.
     *
     * @return array
     *   The form elements for the formatter settings.
     */
    public function settingsForm(array $form, FormStateInterface $form_state);
    
    /**
     * Returns a short summary for the current formatter settings.
     *
     * If an empty result is returned, a UI can still be provided to display
     * a settings form in case the formatter has configurable settings.
     *
     * @return string[]
     *   A short summary of the formatter settings.
     */
    public function settingsSummary();
    
    /**
     * Allows formatters to load information for field values being displayed.
     *
     * This should be used when a formatter needs to load additional information
     * from the database in order to render a field, for example a reference
     * field that displays properties of the referenced entities such as name or
     * type.
     *
     * This method operates on multiple entities. The $entities_items parameter
     * is an array keyed by entity ID. For performance reasons, information for
     * all involved entities should be loaded in a single query where possible.
     *
     * Changes or additions to field values are done by directly altering the
     * items.
     *
     * @param \Drupal\Core\Field\FieldItemListInterface[] $entities_items
     *   An array with the field values from the multiple entities being rendered.
     */
    public function prepareView(array $entities_items);
    
    /**
     * Builds a renderable array for a fully themed field.
     *
     * @param \Drupal\Core\Field\FieldItemListInterface $items
     *   The field values to be rendered.
     * @param string $langcode
     *   (optional) The language that should be used to render the field. Defaults
     *   to the current content language.
     *
     * @return array
     *   A renderable array for a themed field with its label and all its values.
     */
    public function view(FieldItemListInterface $items, $langcode = NULL);
    
    /**
     * Builds a renderable array for a field value.
     *
     * @param \Drupal\Core\Field\FieldItemListInterface $items
     *   The field values to be rendered.
     * @param string $langcode
     *   The language that should be used to render the field.
     *
     * @return array
     *   A renderable array for $items, as an array of child elements keyed by
     *   consecutive numeric indexes starting from 0.
     */
    public function viewElements(FieldItemListInterface $items, $langcode);
    
    /**
     * Returns if the formatter can be used for the provided field.
     *
     * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
     *   The field definition that should be checked.
     *
     * @return bool
     *   TRUE if the formatter can be used, FALSE otherwise.
     */
    public static function isApplicable(FieldDefinitionInterface $field_definition);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
FormatterInterface::isApplicable public static function Returns if the formatter can be used for the provided field. 1
FormatterInterface::prepareView public function Allows formatters to load information for field values being displayed. 1
FormatterInterface::settingsForm public function Returns a form to configure settings for the formatter. 1
FormatterInterface::settingsSummary public function Returns a short summary for the current formatter settings. 1
FormatterInterface::view public function Builds a renderable array for a fully themed field. 1
FormatterInterface::viewElements public function Builds a renderable array for a field value. 48
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 6
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2
PluginSettingsInterface::defaultSettings public static function Defines the default settings for this plugin. 1
PluginSettingsInterface::getSetting public function Returns the value of a setting, or its default value if absent. 1
PluginSettingsInterface::getSettings public function Returns the array of settings, including defaults for missing settings. 1
PluginSettingsInterface::onDependencyRemoval public function Informs the plugin that some configuration it depends on will be deleted. 1
PluginSettingsInterface::setSetting public function Sets the value of a setting for the plugin. 1
PluginSettingsInterface::setSettings public function Sets the settings for the plugin. 1
ThirdPartySettingsInterface::getThirdPartyProviders public function Gets the list of third parties that store information. 5
ThirdPartySettingsInterface::getThirdPartySetting public function Gets the value of a third-party setting. 5
ThirdPartySettingsInterface::getThirdPartySettings public function Gets all third-party settings of a given module. 5
ThirdPartySettingsInterface::setThirdPartySetting public function Sets the value of a third-party setting. 5
ThirdPartySettingsInterface::unsetThirdPartySetting public function Unsets a third-party setting. 5

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