From b94665f5aec34875c61ac28db847b104026b429e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 26 Apr 2010 14:06:23 +0000 Subject: [PATCH] - Patch #688334 by stella, BTMash, carlos8f, chx: fixed file inheritance is broken. --- includes/menu.inc | 9 ++++++--- modules/simpletest/tests/menu.test | 9 +++++++++ modules/simpletest/tests/menu_test.module | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/includes/menu.inc b/includes/menu.inc index 39f7dddade9..8c2255067fb 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -3166,12 +3166,15 @@ function _menu_router_build($callbacks) { if (!isset($item['page arguments']) && isset($parent['page arguments'])) { $item['page arguments'] = $parent['page arguments']; } - if (!isset($item['file']) && isset($parent['file'])) { - $item['file'] = $parent['file']; - } if (!isset($item['file path']) && isset($parent['file path'])) { $item['file path'] = $parent['file path']; } + if (!isset($item['file']) && isset($parent['file'])) { + $item['file'] = $parent['file']; + if (empty($item['file path']) && isset($item['module']) && isset($parent['module']) && $item['module'] != $parent['module']) { + $item['file path'] = drupal_get_path('module', $parent['module']); + } + } } // Same for delivery callbacks. if (!isset($item['delivery callback']) && isset($parent['delivery callback'])) { diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index d9563a86a19..0e6da766b1b 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -51,6 +51,15 @@ class MenuRouterTestCase extends DrupalWebTestCase { $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); } + /** + * Test that 'page callback', 'file' and 'file path' keys are properly + * inherited from parent menu paths. + */ + function testFileInheritance() { + $this->drupalGet('admin/config/development/file-inheritance'); + $this->assertText('File inheritance test description', t('File inheritance works.')); + } + /** * Test path containing "exotic" characters. */ diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module index 1e436ee59a9..ee8f2ea1b7c 100644 --- a/modules/simpletest/tests/menu_test.module +++ b/modules/simpletest/tests/menu_test.module @@ -173,6 +173,22 @@ function menu_test_menu() { 'context' => MENU_CONTEXT_NONE, ); + // File inheritance tests. This menu item should inherit the page callback + // system_admin_menu_block_page() and therefore render its children as links + // on the page. + $items['admin/config/development/file-inheritance'] = array( + 'title' => 'File inheritance', + 'description' => 'Test file inheritance', + 'access arguments' => array('access content'), + ); + $items['admin/config/development/file-inheritance/inherit'] = array( + 'title' => 'Inherit', + 'description' => 'File inheritance test description', + 'page callback' => 'menu_test_callback', + 'access arguments' => array('access content'), + 'type' => MENU_LOCAL_TASK, + ); + return $items; }