diff --git a/core/includes/menu.inc b/core/includes/menu.inc index ef9f7e2..ed555c4 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -1734,96 +1734,6 @@ function menu_list_system_menus() { } /** - * Returns an array of links to be rendered as the Main menu. - */ -function menu_main_menu() { - $config = config('menu.settings'); - $menu_enabled = module_exists('menu'); - // When menu module is not enabled, we need a hardcoded default value. - $main_links_source = $menu_enabled ? $config->get('main_links') : 'main'; - return menu_navigation_links($main_links_source); -} - -/** - * Returns an array of links to be rendered as the Secondary links. - */ -function menu_secondary_menu() { - $config = config('menu.settings'); - $menu_enabled = module_exists('menu'); - // When menu module is not enabled, we need a hardcoded default value. - $main_links_source = $menu_enabled ? $config->get('main_links') : 'main'; - $secondary_links_source = $menu_enabled ? $config->get('secondary_links') : 'account'; - - // If the secondary menu source is set as the primary menu, we display the - // second level of the primary menu. - if ($secondary_links_source == $main_links_source) { - return menu_navigation_links($main_links_source, 1); - } - else { - return menu_navigation_links($secondary_links_source, 0); - } -} - -/** - * Returns an array of links for a navigation menu. - * - * @param $menu_name - * The name of the menu. - * @param $level - * Optional, the depth of the menu to be returned. - * - * @return - * An array of links of the specified menu and level. - */ -function menu_navigation_links($menu_name, $level = 0) { - // Don't even bother querying the menu table if no menu is specified. - if (empty($menu_name)) { - return array(); - } - - // Get the menu hierarchy for the current page. - $tree = menu_tree_page_data($menu_name, $level + 1); - - // Go down the active trail until the right level is reached. - while ($level-- > 0 && $tree) { - // Loop through the current level's items until we find one that is in trail. - while ($item = array_shift($tree)) { - if ($item['link']['in_active_trail']) { - // If the item is in the active trail, we continue in the subtree. - $tree = empty($item['below']) ? array() : $item['below']; - break; - } - } - } - - // Create a single level of links. - $router_item = menu_get_item(); - $links = array(); - foreach ($tree as $item) { - if (!$item['link']['hidden']) { - $class = ''; - $l = $item['link']['localized_options']; - $l['href'] = $item['link']['href']; - $l['title'] = $item['link']['title']; - if ($item['link']['in_active_trail']) { - $class = ' active-trail'; - $l['attributes']['class'][] = 'active-trail'; - } - // Normally, l() compares the href of every link with the current path and - // sets the active class accordingly. But local tasks do not appear in - // menu trees, so if the current path is a local task, and this link is - // its tab root, then we have to set the class manually. - if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != current_path()) { - $l['attributes']['class'][] = 'active'; - } - // Keyed with the unique mlid to generate classes in theme_links(). - $links['menu-' . $item['link']['mlid'] . $class] = $l; - } - } - return $links; -} - -/** * Collects the local tasks (tabs), action links, and the root path. * * @param $level diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8172073..3b98195 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2839,8 +2839,6 @@ function template_preprocess_page(&$variables) { $variables['language'] = $language_interface; $variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr'; $variables['logo'] = theme_get_setting('logo'); - $variables['main_menu'] = theme_get_setting('toggle_main_menu') ? menu_main_menu() : array(); - $variables['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? menu_secondary_menu() : array(); $variables['action_links'] = menu_local_actions(); $variables['site_name'] = (theme_get_setting('toggle_name') ? check_plain($site_config->get('name')) : ''); $variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? filter_xss_admin($site_config->get('slogan')) : ''); diff --git a/core/modules/block/tests/themes/block_test_theme/block_test_theme.info b/core/modules/block/tests/themes/block_test_theme/block_test_theme.info index 6b15fe5..5c20015 100644 --- a/core/modules/block/tests/themes/block_test_theme/block_test_theme.info +++ b/core/modules/block/tests/themes/block_test_theme/block_test_theme.info @@ -3,6 +3,8 @@ description = Theme for testing the block system core = 8.x hidden = TRUE +regions[account] = Account links +regions[main_menu] = Main menu regions[sidebar_first] = Left sidebar regions_hidden[] = sidebar_first regions[sidebar_second] = Right sidebar diff --git a/core/modules/block/tests/themes/block_test_theme/page.tpl.php b/core/modules/block/tests/themes/block_test_theme/page.tpl.php index ba72882..0e93b1c 100644 --- a/core/modules/block/tests/themes/block_test_theme/page.tpl.php +++ b/core/modules/block/tests/themes/block_test_theme/page.tpl.php @@ -38,15 +38,19 @@ + + + - - + + diff --git a/core/modules/menu/config/menu.settings.yml b/core/modules/menu/config/menu.settings.yml index bd3574e..0b617f8 100644 --- a/core/modules/menu/config/menu.settings.yml +++ b/core/modules/menu/config/menu.settings.yml @@ -1,3 +1 @@ -main_links: main -secondary_links: account override_parent_selector: '0' diff --git a/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuNavigation.php b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuNavigation.php new file mode 100644 index 0000000..2dc43ed --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuNavigation.php @@ -0,0 +1,128 @@ + 'main', + 'level' => 0, + ); + } + + /** + * Implements \Drupal\block\BlockBase::blockForm(). + */ + public function blockForm($form, &$form_state) { + $form['menu'] = array( + '#type' => 'select', + '#title' => t('Source menu'), + '#default_value' => $this->configuration['menu'], + '#options' => menu_get_menus(), + '#required' => TRUE, + ); + $form['level'] = array( + '#type' => 'select', + '#title' => t('Starting level'), + '#default_value' => $this->configuration['level'], + '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8)), + '#required' => TRUE, + ); + + return $form; + } + + /** + * Implements \Drupal\block\BlockBase::blockSubmit(). + */ + public function blockSubmit($form, &$form_state) { + $this->setConfig('menu', $form_state['values']['menu']); + $this->setConfig('level', $form_state['values']['level']); + } + + /** + * Implements \Drupal\block\BlockBase::build(). + */ + public function build() { + // @todo BlockManager fails to merge default settings. + $this->configuration += $this->settings(); + + $menu_name = $this->configuration['menu']; + $level = $this->configuration['level']; + // Get the menu hierarchy for the current page. + $tree = menu_tree_page_data($menu_name, $level + 1); + + // Go down the active trail until the right level is reached. + while ($level-- > 0 && $tree) { + // Loop through the current level's items until we find one that is in trail. + while ($item = array_shift($tree)) { + if ($item['link']['in_active_trail']) { + // If the item is in the active trail, we continue in the subtree. + $tree = empty($item['below']) ? array() : $item['below']; + break; + } + } + } + + // Create a single level of links. + $router_item = menu_get_item(); + $links = array(); + foreach ($tree as $item) { + if (!$item['link']['hidden']) { + $class = ''; + $l = $item['link']['localized_options']; + $l['href'] = $item['link']['href']; + $l['title'] = $item['link']['title']; + if ($item['link']['in_active_trail']) { + $class = ' active-trail'; + $l['attributes']['class'][] = 'active-trail'; + } + // Normally, l() compares the href of every link with the current path and + // sets the active class accordingly. But local tasks do not appear in + // menu trees, so if the current path is a local task, and this link is + // its tab root, then we have to set the class manually. + if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != current_path()) { + $l['attributes']['class'][] = 'active'; + } + // Keyed with the unique mlid to generate classes in theme_links(). + $links['menu-' . $item['link']['mlid'] . $class] = $l; + } + } + // Do not output this entire block if there are no visible/accessible links. + // @todo This is insufficient for the real world. Respect #access. + if (empty($links)) { + return array(); + } + $build = array( + '#theme' => 'links', + '#links' => $links, + ); + if (!empty($this->configuration['id'])) { + $build['#attributes']['id'] = drupal_html_id($this->configuration['id']); + } + return $build; + } + +} diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index 75532b0..e5eed48 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -16,7 +16,7 @@ class MenuTest extends WebTestBase { * * @var array */ - public static $modules = array('menu', 'block'); + public static $modules = array('block', 'menu'); protected $big_user; protected $std_user; @@ -34,6 +34,8 @@ public static function getInfo() { function setUp() { parent::setUp(); + $this->drupalPlaceBlock('menu_navigation', array('region' => 'account'), array('menu' => 'account')); + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); // Create users. @@ -161,6 +163,7 @@ function addCustomMenu() { $this->assertText($label); // Enable the block. + $this->container->get('plugin.manager.block')->clearCachedDefinitions(); $this->drupalPlaceBlock('menu_menu_block:' . $menu_name); return menu_load($menu_name); } diff --git a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDFunctionalTest.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDFunctionalTest.php index 1715255..b93c42f 100644 --- a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDFunctionalTest.php +++ b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDFunctionalTest.php @@ -150,8 +150,8 @@ function testLogin() { // Test logging in via the login block on the front page. state()->delete('openid_test.hook_openid_response_response'); state()->delete('openid_test.hook_openid_response_account'); - $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->submitLoginForm($identity, $this->web_user); + $this->assertUserIsLoggedIn($this->web_user); $response = state()->get('openid_test.hook_openid_response_response'); $account = state()->get('openid_test.hook_openid_response_account'); $this->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.'); @@ -169,7 +169,8 @@ function testLogin() { // Submit form to the OpenID Provider Endpoint. $this->drupalPost(NULL, array(), t('Send')); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->web_user->session_id = $this->session_id; + $this->assertUserIsLoggedIn($this->web_user); // Verify user was redirected away from user/login/openid to an accessible // page. @@ -181,8 +182,8 @@ function testLogin() { $new_identity = 'http://example.com/' . $this->randomName(); state()->set('openid_test.identity', $new_identity); state()->set('openid_test.request_alter', array('checkid_setup' => array('openid.identity' => $new_identity))); - $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->submitLoginForm($identity, $this->web_user); + $this->assertUserIsLoggedIn($this->web_user); $response = state()->get('openid_test.hook_openid_response_response'); $this->assertEqual($response['openid.identity'], $new_identity, 'hook_openid_request_alter() were invoked.'); @@ -222,7 +223,8 @@ function testLoginMaintenanceMode() { // Submit form to the OpenID Provider Endpoint. $this->drupalPost(NULL, array(), t('Send')); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->web_user->session_id = $this->session_id; + $this->assertUserIsLoggedIn($this->web_user); // Verify user was redirected away from user/login/openid to an accessible // page. diff --git a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php index 7389580..eee5c07 100644 --- a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php +++ b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php @@ -86,8 +86,8 @@ function testRegisterUserWithEmailVerification() { $this->drupalLogout(); // Verify that the account was activated. - $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->submitLoginForm($identity, $user); + $this->assertUserIsLoggedIn($user); } /** @@ -119,9 +119,13 @@ function testRegisterUserWithoutEmailVerification() { // Use a User-supplied Identity that is the URL of an XRDS document. $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE)); $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); - $user = user_load_by_name('john'); + // @see WebTestBase::drupalLogin() + if (isset($this->session_id)) { + $user->session_id = $this->session_id; + } + $this->assertUserIsLoggedIn($user); + $this->assertTrue($user, 'User was registered with right username.'); $this->assertEqual($user->mail, 'john@example.com', 'User was registered with right email address.'); $this->assertEqual($user->timezone, 'Europe/London', 'User was registered with right timezone.'); @@ -129,8 +133,8 @@ function testRegisterUserWithoutEmailVerification() { $this->drupalLogout(); - $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); + $this->submitLoginForm($identity, $user); + $this->assertUserIsLoggedIn($user); } /** @@ -260,9 +264,13 @@ function testRegisterUserWithAXButNoSREG() { // Use a User-supplied Identity that is the URL of an XRDS document. $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE)); $this->submitLoginForm($identity); - $this->assertLink(t('Log out'), 0, 'User was logged in.'); - $user = user_load_by_name('john'); + // @see WebTestBase::drupalLogin() + if (isset($this->session_id)) { + $user->session_id = $this->session_id; + } + $this->assertUserIsLoggedIn($user); + $this->assertTrue($user, 'User was registered with right username.'); $this->assertEqual($user->mail, 'john@example.com', 'User was registered with right email address.'); $this->assertEqual($user->timezone, 'Europe/London', 'User was registered with right timezone.'); diff --git a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDTestBase.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDTestBase.php index 3110d88..ea44b8e 100644 --- a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDTestBase.php +++ b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDTestBase.php @@ -38,7 +38,7 @@ function setUp() { /** * Initiates the login procedure using the specified User-supplied Identity. */ - function submitLoginForm($identity) { + function submitLoginForm($identity, $account = NULL) { // Fill out and submit the login form. $edit = array('openid_identifier' => $identity); $this->drupalPost('', $edit, t('Log in'), array(), array(), 'openid-login-form'); @@ -48,6 +48,9 @@ function submitLoginForm($identity) { // Submit form to the OpenID Provider Endpoint. $this->drupalPost(NULL, array(), t('Send')); + if (isset($account) && isset($this->session_id)) { + $account->session_id = $this->session_id; + } } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index f886992..86bffb6 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -343,9 +343,6 @@ protected function drupalCreateContentType($settings = array()) { /** * Creates a block instance based on default settings. * - * Note: Until this can be done programmatically, the active user account - * must have permission to administer blocks. - * * @param string $plugin_id * The plugin ID of the block type for this block instance. * @param array $values @@ -368,8 +365,7 @@ protected function drupalCreateContentType($settings = array()) { * @return \Drupal\block\Plugin\Core\Entity\Block * The block entity. * - * @todo - * Add support for creating custom block instances. + * @todo Add support for creating custom block instances. */ protected function drupalPlaceBlock($plugin_id, array $values = array(), array $settings = array()) { $values += array( @@ -639,13 +635,23 @@ protected function drupalLogin($account) { if (isset($this->session_id)) { $account->session_id = $this->session_id; } - $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', array('%name' => $account->name)), 'User login'); + $pass = $this->assertUserIsLoggedIn($account); if ($pass) { $this->loggedInUser = $account; } } /** + * Asserts that a given user account is logged in. + * + * @param $account + * A user object to assert. + */ + protected function assertUserIsLoggedIn($account) { + return $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name is logged in.', array('%name' => $account->name)), 'User login'); + } + + /** * Returns whether a given user account is logged in. * * @param \Drupal\user\User $account diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php index 39494fd..d0a2903 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -263,6 +263,8 @@ function testThemeCallbackHookCustomTheme() { * Tests for menu_link_maintain(). */ function testMenuLinkMaintain() { + $this->drupalPlaceBlock('menu_navigation', array('region' => 'main_menu'), array('menu' => 'main')); + $admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration')); $this->drupalLogin($admin_user); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 83d1746..061a166 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2971,6 +2971,8 @@ function _system_rebuild_theme_data() { $defaults = array( 'engine' => 'phptemplate', 'regions' => array( + 'account' => 'Account links', + 'main_menu' => 'Main navigation', 'sidebar_first' => 'Left sidebar', 'sidebar_second' => 'Right sidebar', 'content' => 'Content', diff --git a/core/modules/system/templates/page.tpl.php b/core/modules/system/templates/page.tpl.php index 6ddeeed..fd6e3cc 100644 --- a/core/modules/system/templates/page.tpl.php +++ b/core/modules/system/templates/page.tpl.php @@ -29,10 +29,6 @@ * in theme settings. * * Navigation: - * - $main_menu (array): An array containing the Main menu links for the - * site, if they have been configured. - * - $secondary_menu (array): An array containing the Secondary menu links for - * the site, if they have been configured. * - $breadcrumb: The breadcrumb trail for the current page. * * Page content (in order of occurrence in the default page.tpl.php): @@ -56,6 +52,8 @@ * comment/reply/12345). * * Regions: + * - $page['account']: Items for the account region. + * - $page['main_menu']: Items for the main menu region. * - $page['help']: Dynamic help text, mostly for admin pages. * - $page['highlighted']: Items for the highlighted content region. * - $page['content']: The main content of the current page. @@ -102,14 +100,18 @@ + + + - + diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php index 6780cf7..168a64d 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php @@ -29,6 +29,15 @@ public static function getInfo() { ); } + function setUp() { + parent::setUp(); + $this->block = $this->drupalPlaceBlock('menu_navigation', array('region' => 'account'), array( + 'menu' => 'account', + 'level' => 0, + 'id' => 'secondary-menu', + )); + } + /** * Tests the secondary menu. */ @@ -38,7 +47,7 @@ function testSecondaryMenu() { // Log in and get the homepage. $this->drupalLogin($user); - $this->drupalGet(''); + $this->drupalGet(''); // For a logged-in user, expect the secondary menu to have links for "My // account" and "Log out". @@ -58,11 +67,16 @@ function testSecondaryMenu() { // Log out and get the homepage. $this->drupalLogout(); - $this->drupalGet(''); + $this->drupalGet(''); // For a logged-out user, expect no secondary links. $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu')); $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.'); + // The wrapping list should not appear either. + $settings = $this->block->get('settings'); + $this->assertNoRaw($settings['id']); + // The entire menu block should not appear either. + $this->assertNoRaw(check_plain($this->block->label())); } /** diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php index f103abf..ca7eea9 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php @@ -72,7 +72,11 @@ function testUserPasswordReset() { // Check successful login. $this->drupalPost(NULL, NULL, t('Log in')); - $this->assertLink(t('Log out')); + // @see WebTestBase::drupalLogin() + if (isset($this->session_id)) { + $this->account->session_id = $this->session_id; + } + $this->assertUserIsLoggedIn($this->account); $this->assertTitle(t('@name | @site', array('@name' => $this->account->name, '@site' => variable_get('site_name', 'Drupal'))), 'Logged in using password reset link.'); // Log out, and try to log in again using the same one-time link. diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/MenuTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/MenuTest.php index 9c9ab60..b0e8d09 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/MenuTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/MenuTest.php @@ -12,6 +12,8 @@ */ class MenuTest extends WizardTestBase { + public static $modules = array('block', 'menu'); + public static function getInfo() { return array( 'name' => 'Menu functionality', @@ -20,6 +22,11 @@ public static function getInfo() { ); } + function setUp() { + parent::setUp(); + $this->drupalPlaceBlock('menu_navigation', array('region' => 'main_menu'), array('menu' => 'main')); + } + /** * Tests the menu functionality. */ diff --git a/core/profiles/standard/config/block.block.bartik.account_links.yml b/core/profiles/standard/config/block.block.bartik.account_links.yml new file mode 100644 index 0000000..97b183c --- /dev/null +++ b/core/profiles/standard/config/block.block.bartik.account_links.yml @@ -0,0 +1,13 @@ +id: bartik.account_links +label: 'Account links' +region: account +weight: '0' +module: menu +status: '1' +plugin: menu_navigation +settings: + menu: account + level: '0' + id: secondary-menu + subject: 'Menu Navigation' +langcode: und diff --git a/core/profiles/standard/config/block.block.bartik.main_menu.yml b/core/profiles/standard/config/block.block.bartik.main_menu.yml new file mode 100644 index 0000000..895c255 --- /dev/null +++ b/core/profiles/standard/config/block.block.bartik.main_menu.yml @@ -0,0 +1,13 @@ +id: bartik.main_menu +label: 'Main menu' +region: main_menu +weight: '0' +module: menu +status: '1' +plugin: menu_navigation +settings: + menu: main + level: '0' + id: main-menu + subject: 'Menu Navigation' +langcode: und diff --git a/core/themes/bartik/bartik.info b/core/themes/bartik/bartik.info index c0c206d..acdc4d0 100644 --- a/core/themes/bartik/bartik.info +++ b/core/themes/bartik/bartik.info @@ -9,7 +9,9 @@ stylesheets[all][] = css/style.css stylesheets[all][] = css/colors.css stylesheets[print][] = css/print.css +regions[account] = Account links regions[header] = Header +regions[main_menu] = Main menu regions[help] = Help regions[page_top] = Page top regions[page_bottom] = Page bottom diff --git a/core/themes/bartik/template.php b/core/themes/bartik/template.php index 9a6c8a9..0f07e5a 100644 --- a/core/themes/bartik/template.php +++ b/core/themes/bartik/template.php @@ -5,6 +5,8 @@ * Functions to support theming in the Bartik theme. */ +use Drupal\block\Plugin\Core\Entity\Block; + /** * Implements hook_preprocess_HOOK() for html.tpl.php. * @@ -151,3 +153,37 @@ function bartik_field__taxonomy_term_reference($variables) { return $output; } + +/** + * Implements hook_block_view_alter(). + */ +function bartik_block_view_alter(array &$build, Block $block) { + if ($block->id() == 'bartik.main_menu') { + $build['#prefix'] = ''; + $build['#theme'] = 'links__system_main_menu'; + $build['#attributes'] = array( + 'id' => 'main-menu-links', + 'class' => array('links', 'clearfix'), + ); + $build['#heading'] = array( + 'text' => t('Main menu'), + 'level' => 'h2', + 'class' => array('element-invisible'), + ); + } + if ($block->id() == 'bartik.account_links') { + $build['#prefix'] = ''; + $build['#theme'] = 'links__system_secondary_menu'; + $build['#attributes'] = array( + 'id' => 'secondary-menu-links', + 'class' => array('links', 'inline', 'clearfix'), + ); + $build['#heading'] = array( + 'text' => t('Secondary menu'), + 'level' => 'h2', + 'class' => array('element-invisible'), + ); + } +} diff --git a/core/themes/bartik/templates/page.tpl.php b/core/themes/bartik/templates/page.tpl.php index 08cc357..b6f6a01 100644 --- a/core/themes/bartik/templates/page.tpl.php +++ b/core/themes/bartik/templates/page.tpl.php @@ -36,10 +36,6 @@ * make the site slogan visually hidden, but still accessible. * * Navigation: - * - $main_menu (array): An array containing the Main menu links for the - * site, if they have been configured. - * - $secondary_menu (array): An array containing the Secondary menu links for - * the site, if they have been configured. * - $breadcrumb: The breadcrumb trail for the current page. * * Page content (in order of occurrence in the default page.tpl.php): @@ -63,7 +59,9 @@ * comment/reply/12345). * * Regions: + * - $page['account']: Items for the account region. * - $page['header']: Items for the header region. + * - $page['main_menu']: Items for the main menu region. * - $page['featured']: Items for the featured region. * - $page['highlighted']: Items for the highlighted content region. * - $page['help']: Dynamic help text, mostly for admin pages. @@ -89,24 +87,8 @@ ?>
-