You are here

public function ExampleEntityEventSubscribers::alterEntityView in Hook Event Dispatcher 8

Alter entity view.

Parameters

\Drupal\hook_event_dispatcher\Event\Entity\EntityViewEvent $event: The event.

File

src/Example/ExampleEntityEventSubscribers.php, line 35

Class

ExampleEntityEventSubscribers
Class ExampleEntityEventSubscribers.

Namespace

Drupal\hook_event_dispatcher\Example

Code

public function alterEntityView(EntityViewEvent $event) {
  $entity = $event
    ->getEntity();

  // Only do this for entities of type Node.
  if ($entity instanceof NodeInterface) {
    $build =& $event
      ->getBuild();
    $build['extra_markup'] = [
      '#markup' => 'this is extra markup',
    ];
  }
}