You are here

public function ExampleEntityEventSubscribers::alterEntityView in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x examples/ExampleEntityEventSubscribers.php \Drupal\hook_event_dispatcher\ExampleEntityEventSubscribers::alterEntityView()

Alter entity view.

Parameters

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

File

examples/ExampleEntityEventSubscribers.php, line 34

Class

ExampleEntityEventSubscribers
Class ExampleEntityEventSubscribers.

Namespace

Drupal\hook_event_dispatcher

Code

public function alterEntityView(EntityViewEvent $event) : void {
  $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',
    ];
  }
}