You are here

public function MenutrailbypathMenuHelper::getMenuLinks in Menu Trail By Path 7.3

Get menu_links for a given menu_name

Parameters

$menu_name:

Return value

array

File

src/MenutrailbypathMenuHelper.inc, line 51

Class

MenutrailbypathMenuHelper

Code

public function getMenuLinks($menu_name) {
  $cid = 'menu_trail_by_path:menu_links:' . $menu_name . ':' . $this->language->language;
  $cache = cache_get($cid, 'cache_menu');
  if (!empty($cache->data)) {
    $menu_links = $cache->data;
  }
  if (!isset($menu_links)) {
    $query = db_select('menu_links', 'ml')
      ->fields('ml')
      ->condition('menu_name', $menu_name, '=')
      ->condition('hidden', 0)
      ->orderBy('depth')
      ->orderBy('weight')
      ->orderBy('mlid');
    if (module_exists('i18n_menu')) {
      $query
        ->condition('language', array(
        LANGUAGE_NONE,
        $this->language->language,
      ), 'IN');
    }
    $results = $query
      ->execute();
    $menu_links = $results instanceof DatabaseStatementInterface ? $this
      ->translateMenuLinkTitles($results
      ->fetchAll()) : array();
    foreach ($menu_links as &$menu_link) {
      $menu_link->menu_path_by_trail_url = $this->urlHelper
        ->getUrl($menu_link->link_path);
    }
    cache_set($cid, $menu_links, 'cache_menu');
  }
  return $menu_links;
}