You are here

public function ExamplePreprocessorEventSubscriber::preprocessBlock in Hook Event Dispatcher 8

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

Parameters

\Drupal\hook_event_dispatcher\Event\Preprocess\BlockPreprocessEvent $event: Event.

File

src/Example/ExamplePreprocessorEventSubscriber.php, line 48

Class

ExamplePreprocessorEventSubscriber
Class ExamplePreprocessorEventSubscriber.

Namespace

Drupal\hook_event_dispatcher\Example

Code

public function preprocessBlock(BlockPreprocessEvent $event) {

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