Drupal 8  8.0.2
FormatterBase Class Reference
Inheritance diagram for FormatterBase:

Public Member Functions

 __construct ($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings)
 view (FieldItemListInterface $items, $langcode=NULL)
 settingsForm (array $form, FormStateInterface $form_state)
 settingsSummary ()
 prepareView (array $entities_items)
- Public Member Functions inherited from PluginSettingsBase
 getSettings ()
 getSetting ($key)
 setSettings (array $settings)
 setSetting ($key, $value)
 getThirdPartySettings ($module=NULL)
 getThirdPartySetting ($module, $key, $default=NULL)
 setThirdPartySetting ($module, $key, $value)
 unsetThirdPartySetting ($module, $key)
 getThirdPartyProviders ()
 calculateDependencies ()
 onDependencyRemoval (array $dependencies)
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 getPluginDefinition ()
- Public Member Functions inherited from FormatterInterface
 viewElements (FieldItemListInterface $items, $langcode)

Static Public Member Functions

static isApplicable (FieldDefinitionInterface $field_definition)
- Static Public Member Functions inherited from PluginSettingsBase
static defaultSettings ()

Protected Member Functions

 getFieldSettings ()
 getFieldSetting ($setting_name)
- Protected Member Functions inherited from PluginSettingsBase
 mergeDefaults ()

Protected Attributes

- Protected Attributes inherited from PluginSettingsBase
 $settings = array()
 $thirdPartySettings = array()
 $defaultSettingsMerged = FALSE

Detailed Description

Base class for 'Field formatter' plugin implementations.

Constructor & Destructor Documentation

__construct (   $plugin_id,
FieldDefinitionInterface  $field_definition,
array  $settings,
array  $third_party_settings 

Constructs a FormatterBase object.

string$plugin_idThe plugin_id for the formatter.
mixed$plugin_definitionThe plugin implementation definition.
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe definition of the field to which the formatter is associated.
array$settingsThe formatter settings.
string$labelThe formatter label display setting.
string$view_modeThe view mode.
array$third_party_settingsAny third party settings.

Member Function Documentation

getFieldSetting (   $setting_name)

Returns the value of a field setting.

string$setting_nameThe setting name.
mixed The setting value.

Referenced by DateTimePlainFormatter\formatDate(), ImageFormatterBase\getEntitiesToView(), BooleanFormatter\getOutputFormats(), EntityReferenceFormatterBase\prepareView(), EntityReferenceEntityFormatter\settingsForm(), EntityReferenceEntityFormatter\settingsSummary(), DateTimeTimeAgoFormatter\viewElements(), and CommentDefaultFormatter\viewElements().

Here is the caller graph for this function:

getFieldSettings ( )

Returns the array of field settings.

array The array of settings.

Referenced by NumericFormatterBase\viewElements(), and CommentDefaultFormatter\viewElements().

Here is the caller graph for this function:

static isApplicable ( FieldDefinitionInterface  $field_definition)

{Returns if the formatter can be used for the provided field.

\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe field definition that should be checked.
bool TRUE if the formatter can be used, FALSE otherwise.

Implements FormatterInterface.

prepareView ( array  $entities_items)

{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.

\Drupal\Core\Field\FieldItemListInterface[]$entities_items An array with the field values from the multiple entities being rendered.

Implements FormatterInterface.

settingsForm ( array  $form,
FormStateInterface  $form_state 

{Returns a form to configure settings for the formatter.Invoked from to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

array$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
array The form elements for the formatter settings.

Implements FormatterInterface.

settingsSummary ( )

{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.

string[] A short summary of the formatter settings.

Implements FormatterInterface.

view ( FieldItemListInterface  $items,
  $langcode = NULL 

{Builds a renderable array for a fully themed field.

\Drupal\Core\Field\FieldItemListInterface$itemsThe field values to be rendered.
string$langcode(optional) The language that should be used to render the field. Defaults to the current content language.
array A renderable array for a themed field with its label and all its values.

Implements FormatterInterface.

References Element\children(), FieldItemListInterface\getEntity(), FieldItemListInterface\getLangcode(), PluginInspectionInterface\getPluginId(), Drupal\languageManager(), LanguageInterface\TYPE_CONTENT, and FormatterInterface\viewElements().

Here is the call graph for this function:

The documentation for this class was generated from the following file: