diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-18 05:28:43 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-18 05:28:43 +0000 |
commit | 1650fea5d949b576bcc779d6315250da0ba7ec82 (patch) | |
tree | d2bbbd716e9f11754dd881145ae06c2a372f4757 | |
parent | 2484439643f86cbc2da3b4f391eb3e23e51fc94d (diff) | |
download | brdo-1650fea5d949b576bcc779d6315250da0ba7ec82.tar.gz brdo-1650fea5d949b576bcc779d6315250da0ba7ec82.tar.bz2 |
#516150 by David_Rothstein, dropcube, Senpai, alexanderpas, sun: Add fallback for main content block rendering. (Make it so you can't render your site completely unusable by disabling block module. Oopsie.)
-rw-r--r-- | includes/common.inc | 16 | ||||
-rw-r--r-- | includes/theme.inc | 12 | ||||
-rw-r--r-- | modules/simpletest/tests/system_test.module | 49 | ||||
-rw-r--r-- | modules/system/system.test | 82 |
4 files changed, 153 insertions, 6 deletions
diff --git a/includes/common.inc b/includes/common.inc index a206570cb..bcc07fe29 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4513,10 +4513,17 @@ function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) { */ function drupal_set_page_content($content = NULL) { $content_block = &drupal_static(__FUNCTION__, NULL); + $main_content_display = &drupal_static('system_main_content_added', FALSE); + if (!empty($content)) { $content_block = (is_array($content) ? $content : array('main' => array('#markup' => $content))); } else { + // Indicate that the main content has been requested. We assume that + // the module requesting the content will be adding it to the page. + // A module can indicate that it does not handle the content by setting + // the static variable back to FALSE after calling this function. + $main_content_display = TRUE; return $content_block; } } @@ -4534,6 +4541,8 @@ function drupal_set_page_content($content = NULL) { * @see element_info('page') */ function drupal_render_page($page) { + $main_content_display = &drupal_static('system_main_content_added', FALSE); + // Allow menu callbacks to return strings or arbitrary arrays to render. // If the array returned is not of #type page directly, we need to fill // in the page with defaults. @@ -4551,6 +4560,13 @@ function drupal_render_page($page) { // 'sidebar_first', 'footer', etc. drupal_alter('page', $page); + // If no module has taken care of the main content, add it to the page now. + // This allows the site to still be usable even if no modules that + // control page regions (for example, the Block module) are enabled. + if (!$main_content_display) { + $page['content']['system_main'] = drupal_set_page_content(); + } + return drupal_render($page); } diff --git a/includes/theme.inc b/includes/theme.inc index 2cb9853e1..e8c51d31c 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -2211,20 +2211,20 @@ function template_preprocess_page(&$variables) { // Move some variables to the top level for themer convenience and template cleanliness. $variables['show_messages'] = $variables['page']['#show_messages']; + foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) { + if (!isset($variables['page'][$region_key])) { + $variables['page'][$region_key] = array(); + } + } + // Set up layout variable. $variables['layout'] = 'none'; if (!empty($variables['page']['sidebar_first'])) { $variables['layout'] = 'first'; } - else { - $variables['page']['sidebar_first'] = array(); - } if (!empty($variables['page']['sidebar_second'])) { $variables['layout'] = ($variables['layout'] == 'first') ? 'both' : 'second'; } - else { - $variables['page']['sidebar_second'] = array(); - } $variables['base_path'] = base_path(); $variables['front_page'] = url(); diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index 6926dfe5f..be4d443f5 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -73,6 +73,27 @@ function system_test_menu() { 'type' => MENU_CALLBACK, ); + $items['system-test/main-content-handling'] = array( + 'title' => 'Test main content handling', + 'page callback' => 'system_test_main_content_fallback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + $items['system-test/main-content-fallback'] = array( + 'title' => 'Test main content fallback', + 'page callback' => 'system_test_main_content_fallback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + $items['system-test/main-content-duplication'] = array( + 'title' => 'Test main content duplication', + 'page callback' => 'system_test_main_content_fallback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -226,3 +247,31 @@ function system_test_lock_exit() { return 'FALSE: Lock not acquired in system_test_lock_exit()'; } } + +/** + * Implement hook_page_build(). + */ +function system_test_page_build(&$page) { + $menu_item = menu_get_item(); + $main_content_display = &drupal_static('system_main_content_added', FALSE); + + if ($menu_item['path'] == 'system-test/main-content-handling') { + $page['footer'] = drupal_set_page_content(); + $page['footer']['main']['#markup'] = '<div id="system-test-content">' . $page['footer']['main']['#markup'] . '</div>'; + } + else if ($menu_item['path'] == 'system-test/main-content-fallback') { + drupal_set_page_content(); + $main_content_display = FALSE; + } + else if ($menu_item['path'] == 'system-test/main-content-duplication') { + drupal_set_page_content(); + } +} + +/** + * Menu callback to test main content fallback(). + */ +function system_test_main_content_fallback() { + return t('Content to test main content fallback'); +} + diff --git a/modules/system/system.test b/modules/system/system.test index 4f75cf21d..4f684e876 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -999,7 +999,89 @@ class SystemBlockTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->drupalPost('admin/structure/block/manage/system/powered-by/configure', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block')); } +} + +/** + * Test main content rendering fallback provided by system module. + */ +class SystemMainContentFallback extends DrupalWebTestCase { + protected $admin_user; + protected $web_user; + + public static function getInfo() { + return array( + 'name' => 'Main content rendering fallback', + 'description' => ' Test system module main content rendering fallback.', + 'group' => 'System', + ); + } + + function setUp() { + parent::setUp('system_test'); + + // Create and login admin user. + $this->admin_user = $this->drupalCreateUser(array( + 'access administration pages', + 'administer site configuration', + 'administer blocks', + 'administer nodes', + )); + $this->drupalLogin($this->admin_user); + // Create a web user. + $this->web_user = $this->drupalCreateUser(array('access user profiles', 'access content')); + } + + /** + * Test availability of main content. + */ + function testMainContentFallback() { + $edit = array(); + // Disable the dashboard module, which depends on the block module. + $edit['modules[Core][dashboard][enable]'] = FALSE; + $this->drupalPost('admin/config/modules', $edit, t('Save configuration')); + $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); + // Disable the block module. + $edit['modules[Core][block][enable]'] = FALSE; + $this->drupalPost('admin/config/modules', $edit, t('Save configuration')); + $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); + module_list(TRUE); + $this->assertFalse(module_exists('block'), t('Block module disabled.')); + + // At this point, no region is filled and fallback should be triggered. + $this->drupalGet('admin/config/system/site-information'); + $this->assertField('site_name', t('Admin interface still availble.')); + + // Fallback should not trigger when another module is handling content. + $this->drupalGet('system-test/main-content-handling'); + $this->assertRaw('id="system-test-content"', t('Content handled by another module')); + $this->assertText(t('Content to test main content fallback'), t('Main content still displayed.')); + + // Fallback should trigger when another module + // indicates that it is not handling the content. + $this->drupalGet('system-test/main-content-fallback'); + $this->assertText(t('Content to test main content fallback'), t('Main content fallback properly triggers.')); + + // Fallback should not trigger when another module is handling content. + // Note that this test ensures that no duplicate + // content gets created by the fallback. + $this->drupalGet('system-test/main-content-duplication'); + $this->assertNoText(t('Content to test main content fallback'), t('Main content not duplicated.')); + + // Request a user* page and see if it is displayed. + $this->drupalLogin($this->web_user); + $this->drupalGet('user/' . $this->web_user->uid . '/edit'); + $this->assertField('mail', t('User interface still availble.')); + + // Enable the block module again. + $this->drupalLogin($this->admin_user); + $edit = array(); + $edit['modules[Core][block][enable]'] = 'block'; + $this->drupalPost('admin/config/modules', $edit, t('Save configuration')); + $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); + module_list(TRUE); + $this->assertTrue(module_exists('block'), t('Block module re-enabled.')); + } } class SystemSettingsForm extends DrupalWebTestCase { |