You are here

function context_preprocess_html in Context 8.4

Same name and namespace in other branches
  1. 8 context.module \context_preprocess_html()
  2. 8.0 context.module \context_preprocess_html()
  3. 7.3 context.core.inc \context_preprocess_html()

Implements hook_preprocess_HOOK().

Run the body class context reactions if there are any and let them add classes to the page body.

File

./context.module, line 45
Defines Drupal hooks for context module.

Code

function context_preprocess_html(&$variables) {

  /** @var \Drupal\context\ContextManager $context_manager */
  $context_manager = \Drupal::service('context.manager');

  // Active theme for route.
  $current_theme = \Drupal::service('theme.negotiator')
    ->determineActiveTheme(Drupal::routeMatch());
  foreach ($context_manager
    ->getActiveReactions('body_class') as $reaction) {
    $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $reaction
      ->execute());
  }
  foreach ($context_manager
    ->getActiveReactions('page_title') as $reaction) {
    $variables['head_title']['title'] = Markup::create(trim(strip_tags($reaction
      ->execute())));
  }

  // Disable regions based on regions reaction.
  foreach ($context_manager
    ->getActiveReactions('regions') as $region_reaction) {
    $configuration = $region_reaction
      ->getConfiguration();
    if (isset($configuration['regions'][$current_theme])) {
      foreach ($configuration['regions'][$current_theme] as $region) {
        unset($variables['page'][$region]);
      }
    }
  }
}