public function ExamplePreprocessEventSubscriber::preprocessBlock in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 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_dispatcherCode
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';
}