Drupal 8  8.0.2
EntityReferenceFormatterBase Class Reference
Inheritance diagram for EntityReferenceFormatterBase:

Public Member Functions

 view (FieldItemListInterface $items, $langcode=NULL)
 prepareView (array $entities_items)
- Public Member Functions inherited from FormatterBase
 __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)

Protected Member Functions

 getEntitiesToView (EntityReferenceFieldItemListInterface $items, $langcode)
 needsEntityLoad (EntityReferenceItem $item)
 checkAccess (EntityInterface $entity)
- Protected Member Functions inherited from FormatterBase
 getFieldSettings ()
 getFieldSetting ($setting_name)
- Protected Member Functions inherited from PluginSettingsBase
 mergeDefaults ()

Additional Inherited Members

- Static Public Member Functions inherited from FormatterBase
static isApplicable (FieldDefinitionInterface $field_definition)
- Static Public Member Functions inherited from PluginSettingsBase
static defaultSettings ()
- Protected Attributes inherited from FormatterBase
- Protected Attributes inherited from PluginSettingsBase
 $settings = array()
 $thirdPartySettings = array()
 $defaultSettingsMerged = FALSE

Detailed Description

Parent plugin for entity reference formatters.

Member Function Documentation

checkAccess ( EntityInterface  $entity)

Checks access to the given entity.

By default, entity access is checked. However, a subclass can choose to exclude certain items from entity access checking by immediately granting access.

\Drupal\Core\Entity\EntityInterface$entityThe entity to check.
A cacheable access result.

References AccessibleInterface\access().

Referenced by EntityReferenceFormatterBase\getEntitiesToView().

Here is the call graph for this function:

Here is the caller graph for this function:

getEntitiesToView ( EntityReferenceFieldItemListInterface  $items,

Returns the referenced entities for display.

The method takes care of:

  • checking entity access,
  • placing the entities in the language expected for display. It is thus strongly recommended that formatters use it in their implementation of viewElements($items) rather than dealing with $items directly.

For each entity, the EntityReferenceItem by which the entity is referenced is available in $entity->_referringItem. This is useful for field types that store additional values next to the reference itself.

\Drupal\Core\Field\EntityReferenceFieldItemListInterface$itemsThe item list.
string$langcodeThe language code of the referenced entities to display.
[] The array of referenced entities to display, keyed by delta.
See Also

References EntityReferenceFormatterBase\checkAccess(), CacheableMetadata\createFromObject(), and Drupal\entityManager().

Referenced by GenericFileFormatter\viewElements(), RSSEnclosureFormatter\viewElements(), UrlPlainFormatter\viewElements(), TableFormatter\viewElements(), EntityReferenceIdFormatter\viewElements(), EntityReferenceTaxonomyTermRssFormatter\viewElements(), EntityReferenceLabelFormatter\viewElements(), and EntityReferenceEntityFormatter\viewElements().

Here is the call graph for this function:

Here is the caller graph for this function:

needsEntityLoad ( EntityReferenceItem  $item)

Returns whether the entity referenced by an item needs to be loaded.

\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem$itemThe item to check.
bool TRUE if the entity needs to be loaded.

References EntityReferenceItem\hasNewEntity().

Referenced by EntityReferenceFormatterBase\prepareView().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Loads the entities referenced in that field across all the entities being viewed.

Implements FormatterInterface.

References Drupal\entityManager(), FormatterBase\getFieldSetting(), and EntityReferenceFormatterBase\needsEntityLoad().

Here is the call graph for this function:

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.

See Also

Implements FormatterInterface.

References CacheableMetadata\createFromRenderArray().

Here is the call graph for this function:

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