You are here

public function ExamplePreprocessEventSubscriber::preprocessPage in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 examples/ExamplePreprocessEventSubscriber.php \Drupal\hook_event_dispatcher\ExamplePreprocessEventSubscriber::preprocessPage()

Preprocess a node page to set the node title as page title.

Parameters

\Drupal\preprocess_event_dispatcher\Event\PagePreprocessEvent $event: Event.

File

examples/ExamplePreprocessEventSubscriber.php, line 55

Class

ExamplePreprocessEventSubscriber
Class ExamplePreprocessorEventSubscriber.

Namespace

Drupal\hook_event_dispatcher

Code

public function preprocessPage(PagePreprocessEvent $event) : void {

  /** @var \Drupal\preprocess_event_dispatcher\Variables\PageEventVariables $variables */
  $variables = $event
    ->getVariables();
  $node = $variables
    ->getNode();
  if ($node === NULL) {
    return;
  }
  $variables
    ->set('title', $node
    ->getTitle());
}