function uikit_preprocess_menu__offcanvas

8.x-3.x preprocess.inc uikit_preprocess_menu__offcanvas(&$variables)
8.x-2.x preprocess.inc uikit_preprocess_menu__offcanvas(&$variables)

File

includes/preprocess.inc, line 496
Set up variables to be placed within the template (.html.twig) files.

Code

function uikit_preprocess_menu__offcanvas(&$variables) {
  $items = $variables ['items'];

  foreach ($items as $key => $item) {
    $variables ['items'][$key]['display_item'] = TRUE;
    $variables ['items'][$key]['has_url'] = TRUE;
    $route = $item ['url']->getRouteName();

    if ($route == '<none>') {
      $variables ['items'][$key]['has_url'] = FALSE;
    }

    if ($item ['below']) {
      $variables ['items'][$key]['has_url'] = FALSE;

      foreach ($item ['below'] as $below_key => $below_item) {
        // Set is_divider and is_header variables to FALSE.
        $variables ['items'][$key]['below'][$below_key]['display_item'] = TRUE;
        $variables ['items'][$key]['below'][$below_key]['has_url'] = TRUE;

        // Get the menu item options and menu_item_type, if set. menu_item_type
        // is set by the UIkit Components module.
        $options = $below_item ['url']->getOptions();
        $menu_item_type = isset($options ['menu_item_type']) ? $options ['menu_item_type'] : 0;

        if ($menu_item_type) {
          switch ($menu_item_type) {
            case 'nav_divider':
            case 'nav_header':
              $variables ['items'][$key]['below'][$below_key]['display_item'] = FALSE;
              break;
          }
        }
      }
    }
  }
}

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in