Drupal 8  8.0.2
EntityViewBuilder Class Reference
Inheritance diagram for EntityViewBuilder:

Public Member Functions

 __construct (EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager)
 
 view (EntityInterface $entity, $view_mode= 'full', $langcode=NULL)
 
 viewMultiple (array $entities=array(), $view_mode= 'full', $langcode=NULL)
 
 build (array $build)
 
 buildMultiple (array $build_list)
 
 buildComponents (array &$build, array $entities, array $displays, $view_mode)
 
 getCacheTags ()
 
 resetCache (array $entities=NULL)
 
 viewField (FieldItemListInterface $items, $display_options=array())
 
 viewFieldItem (FieldItemInterface $item, $display=array())
 
- Public Member Functions inherited from EntityHandlerBase
 setModuleHandler (ModuleHandlerInterface $module_handler)
 

Static Public Member Functions

static createInstance (ContainerInterface $container, EntityTypeInterface $entity_type)
 

Protected Member Functions

 getBuildDefaults (EntityInterface $entity, $view_mode)
 
 alterBuild (array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 
 isViewModeCacheable ($view_mode)
 
 getSingleFieldDisplay ($entity, $field_name, $display_options)
 
- Protected Member Functions inherited from EntityHandlerBase
 moduleHandler ()
 

Protected Attributes

 $entityTypeId
 
 $entityType
 
 $entityManager
 
 $cacheBin = 'render'
 
 $languageManager
 
 $singleFieldDisplays
 
- Protected Attributes inherited from EntityHandlerBase
 $moduleHandler
 

Detailed Description

Base class for entity view builders.

Constructor & Destructor Documentation

__construct ( EntityTypeInterface  $entity_type,
EntityManagerInterface  $entity_manager,
LanguageManagerInterface  $language_manager 
)

Constructs a new EntityViewBuilder.

Parameters
\Drupal\Core\Entity\EntityTypeInterface$entity_typeThe entity type definition.
\Drupal\Core\Entity\EntityManagerInterface$entity_managerThe entity manager service.
\Drupal\Core\Language\LanguageManagerInterface$language_managerThe language manager.

References Drupal\entityManager(), EntityTypeInterface\id(), and Drupal\languageManager().

Here is the call graph for this function:

Member Function Documentation

alterBuild ( array &  $build,
EntityInterface  $entity,
EntityViewDisplayInterface  $display,
  $view_mode 
)
protected

Specific per-entity building.

Parameters
array$buildThe render array that is being created.
\Drupal\Core\Entity\EntityInterface$entityThe entity to be prepared.
\Drupal\Core\Entity\Display\EntityViewDisplayInterface$displayThe entity view display holding the display options configured for the entity components.
string$view_modeThe view mode that should be used to prepare the entity.

Referenced by EntityViewBuilder\buildMultiple().

Here is the caller graph for this function:

build ( array  $build)

Builds an entity's view; augments entity defaults.

This function is assigned as a #pre_render callback in ::view().

It transforms the renderable array for a single entity to the same structure as if we were rendering multiple entities, and then calls the default ::buildMultiple() #pre_render callback.

Parameters
array$buildA renderable array containing build information and context for an entity view.
Returns
array The updated renderable array.
See Also
drupal_render()

References EntityViewBuilder\buildMultiple().

Here is the call graph for this function:

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

Implements EntityViewBuilderInterface.

References EntityHandlerBase\moduleHandler().

Referenced by EntityViewBuilder\buildMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

buildMultiple ( array  $build_list)

Builds multiple entities' views; augments entity defaults.

This function is assigned as a #pre_render callback in ::viewMultiple().

By delaying the building of an entity until the #pre_render processing in drupal_render(), the processing cost of assembling an entity's renderable array is saved on cache-hit requests.

Parameters
array$build_listA renderable array containing build information and context for an entity view.
Returns
array The updated renderable array.
See Also
drupal_render()

References EntityViewBuilder\alterBuild(), EntityViewBuilder\buildComponents(), Element\children(), EntityViewDisplay\collectRenderDisplays(), and EntityHandlerBase\moduleHandler().

Referenced by EntityViewBuilder\build(), and BlockContentViewBuilder\viewMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

static createInstance ( ContainerInterface  $container,
EntityTypeInterface  $entity_type 
)
static

{Instantiates a new instance of this entity handler.This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

Parameters
\Symfony\Component\DependencyInjection\ContainerInterface$containerThe service container this object should use.
\Drupal\Core\Entity\EntityTypeInterface$entity_typeThe entity type definition.
Returns
static A new instance of the entity handler.
}

Implements EntityHandlerInterface.

References EntityTypeInterface\get().

Here is the call graph for this function:

getBuildDefaults ( EntityInterface  $entity,
  $view_mode 
)
protected

Provides entity-specific defaults to the build process.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity for which the defaults should be provided.
string$view_modeThe view mode that should be used.
Returns
array

References CacheableDependencyInterface\getCacheContexts(), CacheableDependencyInterface\getCacheMaxAge(), CacheableDependencyInterface\getCacheTags(), EntityViewBuilder\getCacheTags(), EntityInterface\id(), EntityInterface\isNew(), EntityViewBuilder\isViewModeCacheable(), EntityInterface\language(), Cache\mergeTags(), and EntityHandlerBase\moduleHandler().

Referenced by EntityViewBuilder\viewMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements EntityViewBuilderInterface.

Referenced by EntityViewBuilder\getBuildDefaults(), and EntityViewBuilder\resetCache().

Here is the caller graph for this function:

getSingleFieldDisplay (   $entity,
  $field_name,
  $display_options 
)
protected

Gets an EntityViewDisplay for rendering an individual field.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity.
string$field_nameThe field name.
string | array$display_optionsThe display options passed to the viewField() method.
Returns

Referenced by EntityViewBuilder\viewField().

Here is the caller graph for this function:

isViewModeCacheable (   $view_mode)
protected

Determines whether the view mode is cacheable.

Parameters
string$view_modeName of the view mode that should be rendered.
Returns
bool TRUE if the view mode can be cached, FALSE otherwise.

References Drupal\entityManager().

Referenced by EntityViewBuilder\getBuildDefaults().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements EntityViewBuilderInterface.

References EntityViewBuilder\getCacheTags(), Cache\invalidateTags(), and Cache\mergeTags().

Here is the call graph for this function:

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

Implements EntityViewBuilderInterface.

References EntityViewBuilder\viewMultiple().

Here is the call graph for this function:

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()
}

Implements EntityViewBuilderInterface.

References FieldItemListInterface\getEntity(), FieldItemListInterface\getFieldDefinition(), and EntityViewBuilder\getSingleFieldDisplay().

Here is the call graph for this function:

viewFieldItem ( FieldItemInterface  $item,
  $display = 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()
}

Implements EntityViewBuilderInterface.

References FieldItemInterface\getEntity(), and FieldItemInterface\getFieldDefinition().

Here is the call graph for this function:

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

Implements EntityViewBuilderInterface.

References Drupal\entityManager(), EntityViewBuilder\getBuildDefaults(), and EntityHandlerBase\moduleHandler().

Referenced by BlockViewBuilder\view(), and EntityViewBuilder\view().

Here is the call graph for this function:

Here is the caller graph for this function:

Field Documentation

$languageManager
protected

The language manager.

Parameters
\Drupal\Core\Language\LanguageManagerInterface$language_manager
$singleFieldDisplays
protected

The EntityViewDisplay objects created for individual field rendering.

See Also
::getSingleFieldDisplay()
Parameters
\Drupal\Core\Entity\Display\EntityViewDisplayInterface[]

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