Пример #1
0
function custom_ctools_menu_local_tasks($level = 0, $return_root = FALSE, $pathgroup)
{
    static $tabs;
    static $root_path;
    if (!isset($tabs)) {
        $tabs = array();
        $router_item = menu_get_item($pathgroup, Null);
        if (!$router_item || !$router_item['access']) {
            return '';
        }
        // Get all tabs and the root page.
        $result = db_query("SELECT * FROM {menu_router} WHERE tab_root = '%s' ORDER BY weight, title", $router_item['tab_root']);
        $map = arg(NULL, $pathgroup);
        $children = array();
        $tasks = array();
        $root_path = $router_item['path'];
        while ($item = db_fetch_array($result)) {
            _menu_translate($item, $map, TRUE);
            if ($item['tab_parent']) {
                // All tabs, but not the root page.
                $children[$item['tab_parent']][$item['path']] = $item;
            }
            // Store the translated item for later use.
            $tasks[$item['path']] = $item;
        }
        // Find all tabs below the current path.
        $path = $router_item['path'];
        _ctools_menu_add_dynamic_items($children[$path]);
        // Tab parenting may skip levels, so the number of parts in the path may not
        // equal the depth. Thus we use the $depth counter (offset by 1000 for ksort).
        $depth = 1001;
        while (isset($children[$path])) {
            $tabs_current = '';
            $next_path = '';
            $count = 0;
            foreach ($children[$path] as $item) {
                if ($item['access']) {
                    $count++;
                    // The default task is always active.
                    if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
                        // Find the first parent which is not a default local task.
                        if (isset($item['tab_parent'])) {
                            for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']) {
                            }
                            $href = $tasks[$p]['href'];
                            $next_path = $item['path'];
                        } else {
                            $href = $item['href'];
                        }
                        $link = theme('menu_item_link', array('href' => $href) + $item);
                        $tabs_current .= theme('menu_local_task', $link, TRUE);
                    } else {
                        $link = theme('menu_item_link', $item);
                        $tabs_current .= theme('menu_local_task', $link);
                    }
                }
            }
            $path = $next_path;
            $tabs[$depth]['count'] = $count;
            $tabs[$depth]['output'] = $tabs_current;
            $depth++;
        }
        // Find all tabs at the same level or above the current one.
        $parent = $router_item['tab_parent'];
        $path = $router_item['path'];
        $current = $router_item;
        $depth = 1000;
        while (isset($children[$parent])) {
            $tabs_current = '';
            $next_path = '';
            $next_parent = '';
            $count = 0;
            foreach ($children[$parent] as $item) {
                if ($item['access']) {
                    $count++;
                    if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
                        // Find the first parent which is not a default local task.
                        for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']) {
                        }
                        $link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
                        if ($item['path'] == $router_item['path']) {
                            $root_path = $tasks[$p]['path'];
                        }
                    } else {
                        $link = theme('menu_item_link', $item);
                    }
                    // We check for the active tab.
                    if ($item['path'] == $path) {
                        $tabs_current .= theme('menu_local_task', $link, TRUE);
                        $next_path = $item['tab_parent'];
                        if (isset($tasks[$next_path])) {
                            $next_parent = $tasks[$next_path]['tab_parent'];
                        }
                    } else {
                        $tabs_current .= theme('menu_local_task', $link);
                    }
                }
            }
            $path = $next_path;
            $parent = $next_parent;
            $tabs[$depth]['count'] = $count;
            $tabs[$depth]['output'] = $tabs_current;
            $depth--;
        }
        // Sort by depth.
        ksort($tabs);
        // Remove the depth, we are interested only in their relative placement.
        $tabs = array_values($tabs);
    }
    if ($return_root) {
        return $root_path;
    } else {
        // We do not display single tabs.
        return isset($tabs[$level]) && $tabs[$level]['count'] > 1 ? $tabs[$level]['output'] : '';
    }
}
Пример #2
0
/**
* Get all primary tasks including subsets
*/
function _bootstrap_local_tasks($tabs = FALSE)
{
    if ($tabs == '') {
        return $tabs;
    }
    if (!$tabs) {
        $tabs = menu_primary_local_tasks();
    }
    foreach ($tabs as $key => $element) {
        $result = db_select('menu_router', NULL, array('fetch' => PDO::FETCH_ASSOC))->fields('menu_router')->condition('tab_parent', $element['#link']['path'])->condition('context', MENU_CONTEXT_INLINE, '<>')->condition('type', array(MENU_DEFAULT_LOCAL_TASK, MENU_LOCAL_TASK), 'IN')->orderBy('weight')->orderBy('title')->execute();
        $router_item = menu_get_item($element['#link']['href']);
        $map = $router_item['original_map'];
        $i = 0;
        foreach ($result as $item) {
            _menu_translate($item, $map, TRUE);
            //only add items that we have access to
            if ($item['tab_parent'] && $item['access']) {
                //set path to that of parent for the first item
                if ($i === 0) {
                    $item['href'] = $element['#link']['href'];
                }
                if (current_path() == $item['href']) {
                    $tabs[$key][] = array('#theme' => 'menu_local_task', '#link' => $item, '#active' => TRUE);
                } else {
                    $tabs[$key][] = array('#theme' => 'menu_local_task', '#link' => $item);
                }
                //only count items we have access to.
                $i++;
            }
        }
    }
    return $tabs;
}
Пример #3
0
/**
 * Overrides theme_breadcrumb().
 */
function badm_breadcrumb($variables)
{
    $breadcrumb = $variables['breadcrumb'];
    if (!empty($breadcrumb)) {
        $output = '<h2 class="sr-only">' . t('You are here') . '</h2>';
        if (!empty($breadcrumb)) {
            if (variable_get('badm_breadcrumb_display_home', false)) {
                // Remove first item and set the Home glyphicon, for fun.
                $front = url('<front>');
                array_unshift($breadcrumb, <<<EOT
<a href="{$front}">
  <span aria-hidden="true" class="glyphicon glyphicon-home"></span>
  <span class="sr-only">Home</span>
</a>
EOT
);
            }
            $links = '<li>' . implode('</li><li>', $breadcrumb) . '</li>';
        } else {
            $links = '';
        }
        if (($item = menu_get_item()) && $item['type'] == MENU_LOCAL_TASK) {
            _menu_translate($item, $item['original_map']);
            $current = $item['title'];
        } else {
            $current = drupal_get_title();
        }
        $output .= '<ol class="breadcrumb">' . $links . '<li class="active">' . $current . '</li></ol>';
        return $output;
    }
}