You are here

function brainstorm_theme_preprocess_menu in Brainstorm profile 8

Implements hook_preprocess_HOOK() for node.html.twig.

File

theme/brainstorm_theme/brainstorm_theme.theme, line 72
Process theme data.

Code

function brainstorm_theme_preprocess_menu(&$variables, $hook) {
  if ($hook == 'menu') {
    $current_path = \Drupal::request()
      ->getRequestUri();
    $items = $variables['items'];
    foreach ($items as $key => $item) {

      // Set active to dom element if path of menu item matches current path.
      if ($item['url']
        ->toString() == $current_path) {

        // Add active link.
        $variables['items'][$key]['attributes']
          ->addClass('active');
      }
      else {

        // Set active to dom element.
        $url_fragments = explode('/', $current_path);
        if (count($url_fragments) > 1 && '/' . $url_fragments[1] == $item['url']
          ->toString()) {
          $variables['items'][$key]['attributes']
            ->addClass('active');
        }
      }
    }
  }
}