3 namespace Drupal\Core\Field;
5 use Drupal\Core\Form\FormStateInterface;
8 * Interface definition for field formatter plugins.
10 * @ingroup field_formatter
12 interface FormatterInterface extends PluginSettingsInterface {
15 * Returns a form to configure settings for the formatter.
17 * Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow
18 * administrators to configure the formatter. The field_ui module takes care
19 * of handling submitted form values.
22 * The form where the settings form is being included in.
23 * @param \Drupal\Core\Form\FormStateInterface $form_state
24 * The current state of the form.
27 * The form elements for the formatter settings.
29 public function settingsForm(array $form, FormStateInterface $form_state);
32 * Returns a short summary for the current formatter settings.
34 * If an empty result is returned, a UI can still be provided to display
35 * a settings form in case the formatter has configurable settings.
38 * A short summary of the formatter settings.
40 public function settingsSummary();
43 * Allows formatters to load information for field values being displayed.
45 * This should be used when a formatter needs to load additional information
46 * from the database in order to render a field, for example a reference
47 * field that displays properties of the referenced entities such as name or
50 * This method operates on multiple entities. The $entities_items parameter
51 * is an array keyed by entity ID. For performance reasons, information for
52 * all involved entities should be loaded in a single query where possible.
54 * Changes or additions to field values are done by directly altering the
57 * @param \Drupal\Core\Field\FieldItemListInterface[] $entities_items
58 * An array with the field values from the multiple entities being rendered.
60 public function prepareView(array $entities_items);
63 * Builds a renderable array for a fully themed field.
65 * @param \Drupal\Core\Field\FieldItemListInterface $items
66 * The field values to be rendered.
67 * @param string $langcode
68 * (optional) The language that should be used to render the field. Defaults
69 * to the current content language.
72 * A renderable array for a themed field with its label and all its values.
74 public function view(FieldItemListInterface $items, $langcode = NULL);
77 * Builds a renderable array for a field value.
79 * @param \Drupal\Core\Field\FieldItemListInterface $items
80 * The field values to be rendered.
81 * @param string $langcode
82 * The language that should be used to render the field.
85 * A renderable array for $items, as an array of child elements keyed by
86 * consecutive numeric indexes starting from 0.
88 public function viewElements(FieldItemListInterface $items, $langcode);
91 * Returns if the formatter can be used for the provided field.
93 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
94 * The field definition that should be checked.
97 * TRUE if the formatter can be used, FALSE otherwise.
99 public static function isApplicable(FieldDefinitionInterface $field_definition);