Drupal 8  8.0.2
EntityViewBuilderInterface Interface Reference
Inheritance diagram for EntityViewBuilderInterface:

Public Member Functions

 buildComponents (array &$build, array $entities, array $displays, $view_mode)
 
 view (EntityInterface $entity, $view_mode= 'full', $langcode=NULL)
 
 viewMultiple (array $entities=array(), $view_mode= 'full', $langcode=NULL)
 
 resetCache (array $entities=NULL)
 
 viewField (FieldItemListInterface $items, $display_options=array())
 
 viewFieldItem (FieldItemInterface $item, $display_options=array())
 
 getCacheTags ()
 

Detailed Description

Defines an interface for entity view builders.

Member Function Documentation

buildComponents ( array &  $build,
array  $entities,
array  $displays,
  $view_mode 
)

Builds the component fields and properties of a set of entities.

Parameters
&$buildThe renderable array representing the entity content.
\Drupal\Core\Entity\EntityInterface[]$entities The entities whose content is being built.
\Drupal\Core\Entity\Display\EntityViewDisplayInterface[]$displays The array of entity view displays holding the display options configured for the entity components, keyed by bundle name.
string$view_modeThe view mode in which the entity is being viewed.

Implemented in EntityViewBuilder, BlockViewBuilder, FeedViewBuilder, MessageViewBuilder, EntityTestViewBuilder, and ItemViewBuilder.

getCacheTags ( )

The cache tag associated with this entity view builder.

An entity view builder is instantiated on a per-entity type basis, so the cache tags are also per-entity type.

Returns
array An array of cache tags.

Implemented in EntityViewBuilder.

resetCache ( array  $entities = NULL)

Resets the entity render cache.

Parameters
\Drupal\Core\Entity\EntityInterface[]$entities (optional) If specified, the cache is reset for the given entities only.

Implemented in EntityViewBuilder.

view ( EntityInterface  $entity,
  $view_mode = 'full',
  $langcode = NULL 
)

Builds the render array for the provided entity.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity to render.
string$view_mode(optional) The view mode that should be used to render the entity.
string$langcode(optional) For which language the entity should be rendered, defaults to the current content language.
Returns
array A render array for the entity.
Exceptions
\InvalidArgumentExceptionCan be thrown when the set of parameters is inconsistent, like when trying to view a Comment and passing a Node which is not the one the comment belongs to, or not passing one, and having the comment node not be available for loading.

Implemented in EntityViewBuilder, BlockViewBuilder, MessageViewBuilder, BlockContentViewBuilder, and EntityTestViewBuilderOverriddenView.

viewField ( FieldItemListInterface  $items,
  $display_options = array() 
)

Builds a renderable array for the value of a single field in an entity.

The resulting output is a fully themed field with label and multiple values.

This function can be used by third-party modules that need to output an isolated field.

  • Do not use inside node (or any other entity) templates; use render($content[FIELD_NAME]) instead.
  • The FieldItemInterface::view() method can be used to output a single formatted field value, without label or wrapping field markup.

The function takes care of invoking the prepare_view steps. It also respects field access permissions.

Parameters
\Drupal\Core\Field\FieldItemListInterface$itemsFieldItemList containing the values to be displayed.
string | array$display_optionsCan be either:
  • The name of a view mode. The field will be displayed according to the display settings specified for this view mode in the $field definition for the field in the entity's bundle. If no display settings are found for the view mode, the settings for the 'default' view mode will be used.
  • An array of display options. The following key/value pairs are allowed:
    • label: (string) Position of the label. The default 'field' theme implementation supports the values 'inline', 'above' and 'hidden'. Defaults to 'above'.
    • type: (string) The formatter to use. Defaults to the 'default_formatter' for the field type. The default formatter will also be used if the requested formatter is not available.
    • settings: (array) Settings specific to the formatter. Defaults to the formatter's default settings.
    • weight: (float) The weight to assign to the renderable element. Defaults to 0.
Returns
array A renderable array for the field values.
See Also
::viewFieldItem()

Implemented in EntityViewBuilder.

viewFieldItem ( FieldItemInterface  $item,
  $display_options = array() 
)

Builds a renderable array for a single field item.

Parameters
\Drupal\Core\Field\FieldItemInterface$itemFieldItem to be displayed.
string | array$display_optionsCan be either the name of a view mode, or an array of display settings. See EntityViewBuilderInterface::viewField() for more information.
Returns
array A renderable array for the field item.
See Also
::viewField()

Implemented in EntityViewBuilder.

viewMultiple ( array  $entities = array(),
  $view_mode = 'full',
  $langcode = NULL 
)

Builds the render array for the provided entities.

Parameters
array$entitiesAn array of entities implementing EntityInterface to view.
string$view_mode(optional) The view mode that should be used to render the entity.
string$langcode(optional) For which language the entity should be rendered, defaults to the current content language.
Returns
A render array for the entities, indexed by the same keys as the entities array passed in $entities.
Exceptions
\InvalidArgumentExceptionCan be thrown when the set of parameters is inconsistent, like when trying to view Comments and passing a Node which is not the one the comments belongs to, or not passing one, and having the comments node not be available for loading.

Implemented in EntityViewBuilder, BlockContentViewBuilder, and EntityTestViewBuilderOverriddenView.


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