class EntityViewController implements ContainerInjectionInterface, TrustedCallbackInterface (View source)

Defines a generic controller to render a single entity.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected RendererInterface $renderer

The renderer service.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer)

Creates an EntityViewController object.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

array
buildTitle(array $page)

Pre-render callback to build the page title.

array
view(EntityInterface $_entity, string $view_mode = 'full')

Provides a page to render a single entity.

static string[]
trustedCallbacks()

Lists the trusted callbacks provided by the implementing class.

array
viewRevision(EntityInterface $_entity_revision, string $view_mode = 'full')

Provides a page to render a single entity revision.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer)

Creates an EntityViewController object.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

RendererInterface $renderer

The renderer service.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

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

Parameters

ContainerInterface $container

The service container this instance should use.

array buildTitle(array $page)

Pre-render callback to build the page title.

Parameters

array $page

A page render array.

Return Value

array

The changed page render array.

array view(EntityInterface $_entity, string $view_mode = 'full')

Provides a page to render a single entity.

Parameters

EntityInterface $_entity

The Entity to be rendered. Note this variable is named $_entity rather than $entity to prevent collisions with other named placeholders in the route.

string $view_mode

(optional) The view mode that should be used to display the entity. Defaults to 'full'.

Return Value

array

A render array as expected by \Drupal\Core\Render\RendererInterface::render().

static string[] trustedCallbacks()

Lists the trusted callbacks provided by the implementing class.

Trusted callbacks are public methods on the implementing class and can be invoked via \Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback().

Return Value

string[]

List of method names implemented by the class that can be used as trusted callbacks.

array viewRevision(EntityInterface $_entity_revision, string $view_mode = 'full')

Provides a page to render a single entity revision.

Parameters

EntityInterface $_entity_revision

The Entity to be rendered. Note this variable is named $_entity_revision rather than $entity to prevent collisions with other named placeholders in the route.

string $view_mode

(optional) The view mode that should be used to display the entity. Defaults to 'full'.

Return Value

array

A render array.