You are here

public function ExamplePreprocessEventSubscriber::preprocessBlock in Hook Event Dispatcher 8.2

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

Preprocess blocks with field_contact_form and add contact-form-wrapper id.

Parameters

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

File

examples/ExamplePreprocessEventSubscriber.php, line 73

Class

ExamplePreprocessEventSubscriber
Class ExamplePreprocessorEventSubscriber.

Namespace

Drupal\hook_event_dispatcher

Code

public function preprocessBlock(BlockPreprocessEvent $event) : void {

  /** @var \Drupal\preprocess_event_dispatcher\Variables\BlockEventVariables $variables */
  $variables = $event
    ->getVariables();
  if ($variables
    ->get('field_contact_form') === NULL) {
    return;
  }
  $variables
    ->getByReference('attributes')['id'] = 'contact-form-wrapper';
}