You are here

protected function MenuTrailByPathTestCase::buildMenu in Menu Trail By Path 7.3

Same name and namespace in other branches
  1. 7.2 menu_trail_by_path.test \MenuTrailByPathTestCase::buildMenu()

Build a menu with the data of $this->menuUrls

Parameters

string $menu_name:

1 call to MenuTrailByPathTestCase::buildMenu()
MenuTrailByPathTestCase::setUp in ./menu_trail_by_path.test
Sets up a Drupal site for running functional and integration tests.

File

./menu_trail_by_path.test, line 201
Tests for menu_trail_by_path module.

Class

MenuTrailByPathTestCase
@file Tests for menu_trail_by_path module.

Code

protected function buildMenu($menu_name = 'main-menu') {
  menu_delete_links($menu_name);
  $menuLinks = array();
  $parents = array();
  $weight = -30;

  // Add menu links
  foreach ($this->menuUrls as $link_title => $link_path) {
    $parent = NULL;
    $titles = explode(' » ', $link_title);
    $titleShort = array_pop($titles);
    if ($titles) {
      $parents[] = $parent = $menuLinks[implode(' » ', $titles)]['mlid'];
    }
    $menuLinks[$link_title] = array(
      'menu_name' => $menu_name,
      'link_title' => $titleShort,
      'link_path' => $link_path,
      'plid' => $parent,
      'weight' => $weight,
      'expanded' => 1,
    );
    menu_link_save($menuLinks[$link_title]);
    $weight++;
  }

  // Check if menu links have children
  foreach ($menuLinks as &$menuLink) {
    if (in_array($menuLink['mlid'], $parents)) {
      $menuLink['has_children'] = 1;
      menu_link_save($menuLink);
    }
  }
  unset($menuLink);

  // In a "normal-ish" situation _menu_clear_page_cache, called by menu_link_save,
  // "clears the page and block caches", BUT it does that "at most twice per page load".
  // So we have to do it ourselves...
  cache_clear_all();
  _menu_set_expanded_menus();
}