Commit ff836870 authored by Dries's avatar Dries

- Patch #652122 by sun, catch, moshe weitzman, Berdir, mr.baileys, chx,...

- Patch #652122 by sun, catch, moshe weitzman, Berdir, mr.baileys, chx, David_Rothstein, Scott Reynolds, Damien Tournoud: fix dashboard as the default /admin local task.
parent db7a326d
......@@ -315,12 +315,16 @@ function menu_get_ancestors($parts) {
}
$current = '';
for ($j = $length; $j >= 0; $j--) {
// Check the bit on the $j offset.
if ($i & (1 << $j)) {
// Bit one means the original value.
$current .= $parts[$length - $j];
}
else {
// Bit zero means means wildcard.
$current .= '%';
}
// Unless we are at offset 0, add a slash.
if ($j) {
$current .= '/';
}
......@@ -1735,7 +1739,7 @@ function menu_local_tasks($level = 0) {
return $empty;
}
// Get all tabs and the root page.
// Get all tabs (also known as local tasks) and the root page.
$result = db_select('menu_router', NULL, array('fetch' => PDO::FETCH_ASSOC))
->fields('menu_router')
->condition('tab_root', $router_item['tab_root'])
......@@ -1772,12 +1776,19 @@ function menu_local_tasks($level = 0) {
$tab_count = 0;
$action_count = 0;
foreach ($children[$path] as $item) {
// Local tasks can be normal items too, so bitmask with
// MENU_IS_LOCAL_TASK before checking.
if (!($item['type'] & MENU_IS_LOCAL_TASK)) {
// This item is not a tab, skip it.
continue;
}
if ($item['access']) {
$link = $item;
// The default task is always active.
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
// The default task is always active. As tabs can be normal items
// too, so bitmask with MENU_LINKS_TO_PARENT before checking.
if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
// Find the first parent which is not a default local task or action.
for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']);
for ($p = $item['tab_parent']; ($tasks[$p]['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT; $p = $tasks[$p]['tab_parent']);
// Use the path of the parent instead.
$link['href'] = $tasks[$p]['href'];
$tabs_current[] = array(
......@@ -1789,19 +1800,23 @@ function menu_local_tasks($level = 0) {
$tab_count++;
}
else {
if ($item['type'] == MENU_LOCAL_TASK) {
$tabs_current[] = array(
'#theme' => 'menu_local_task',
// Actions can be normal items too, so bitmask with
// MENU_IS_LOCAL_ACTION before checking.
if (($item['type'] & MENU_IS_LOCAL_ACTION) == MENU_IS_LOCAL_ACTION) {
// The item is an action, display it as such.
$actions_current[] = array(
'#theme' => 'menu_local_action',
'#link' => $link,
);
$tab_count++;
$action_count++;
}
else {
$actions_current[] = array(
'#theme' => 'menu_local_action',
// Otherwise, it's a normal tab.
$tabs_current[] = array(
'#theme' => 'menu_local_task',
'#link' => $link,
);
$action_count++;
$tab_count++;
}
}
}
......@@ -1825,15 +1840,18 @@ function menu_local_tasks($level = 0) {
$next_parent = '';
$count = 0;
foreach ($children[$parent] as $item) {
// Skip local actions.
if ($item['type'] & MENU_IS_LOCAL_ACTION) {
continue;
}
if ($item['access']) {
$count++;
$link = $item;
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
// Local tasks can be normal items too, so bitmask with
// MENU_LINKS_TO_PARENT before checking.
if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
// 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']);
for ($p = $item['tab_parent']; ($tasks[$p]['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT; $p = $tasks[$p]['tab_parent']);
// Use the path of the parent instead.
$link['href'] = $tasks[$p]['href'];
if ($item['path'] == $router_item['path']) {
......@@ -2215,7 +2233,7 @@ function menu_get_active_breadcrumb() {
$end = end($active_trail);
// Don't show a link to the current page in the breadcrumb trail.
if ($item['href'] == $end['href'] || ($item['type'] == MENU_DEFAULT_LOCAL_TASK && $end['href'] != '<front>')) {
if ($item['href'] == $end['href'] || (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT && $end['href'] != '<front>')) {
array_pop($breadcrumb);
}
}
......
......@@ -29,17 +29,18 @@ function dashboard_menu() {
'title' => 'Dashboard',
'description' => 'View and customize your dashboard',
'page callback' => 'dashboard_admin',
'access arguments' => array('access administration pages'),
'access arguments' => array('access dashboard'),
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
// Make this appear first, so for example, in admin menus, it shows up on
// the top corner of the window as a convinient "home link".
'weight' => -100,
'weight' => -15,
);
$items['admin/dashboard/customize'] = array(
'title' => 'Dashboard',
'description' => 'View and customize your dashboard',
'page callback' => 'dashboard_admin',
'page arguments' => array(TRUE),
'access arguments' => array('access administration pages'),
'access arguments' => array('access dashboard'),
'type' => MENU_CALLBACK,
);
$items['admin/dashboard/drawer'] = array(
......@@ -62,14 +63,17 @@ function dashboard_menu() {
}
/**
* Implements hook_menu_alter().
* Implements hook_permission().
*/
function dashboard_menu_alter(&$items) {
// Make the dashboard the default local task on /admin.
$items['admin']['title'] = 'Dashboard';
$items['admin']['page callback'] = 'dashboard_admin';
$items['admin/dashboard']['type'] = MENU_DEFAULT_LOCAL_TASK;
$items['admin/by-task']['type'] = MENU_LOCAL_TASK;
function dashboard_permission() {
return array(
'access dashboard' => array(
'title' => t('View the administrative dashboard'),
'description' => t('Customizing the dashboard requires the !permission-name permission.', array(
'!permission-name' => l(t('Administer blocks'), 'admin/people/permissions', array('fragment' => 'module-block')),
)),
),
);
}
/**
......
......@@ -19,7 +19,7 @@ class DashboardAccessTestCase extends DrupalWebTestCase {
parent::setUp();
// Create and log in an administrative user having access to the dashboard.
$admin_user = $this->drupalCreateUser(array('access administration pages', 'administer blocks'));
$admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks'));
$this->drupalLogin($admin_user);
// Make sure that the dashboard is using the same theme as the rest of the
......@@ -46,14 +46,14 @@ class DashboardAccessTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Ensure admin access.
$this->drupalGet('admin');
$this->drupalGet('admin/dashboard');
$this->assertResponse(200, t('Admin has access to the dashboard.'));
$this->assertRaw($custom_block['title'], t('Admin has access to a dashboard block.'));
// Ensure non-admin access is denied.
$normal_user = $this->drupalCreateUser();
$this->drupalLogin($normal_user);
$this->drupalGet('admin');
$this->drupalGet('admin/dashboard');
$this->assertResponse(403, t('Non-admin has no access to the dashboard.'));
$this->assertNoText($custom_block['title'], t('Non-admin has no access to a dashboard block.'));
}
......
......@@ -543,13 +543,14 @@ function system_menu() {
'access arguments' => array('access administration pages'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'system.admin.inc',
'weight' => -20,
);
$items['admin/by-module'] = array(
'title' => 'By module',
'page callback' => 'system_admin_by_module',
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'weight' => -18,
'file' => 'system.admin.inc',
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment