diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-26 04:45:10 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-26 04:45:10 +0000 |
commit | 7536a354141c48c19109e511acf628c799e168b5 (patch) | |
tree | f8a94046c4f07bc8ce76ddb3128d193bb7a321a5 /modules/toolbar | |
parent | bbce39fff3491d9f8e5386d43a78dddf7459d0b2 (diff) | |
download | brdo-7536a354141c48c19109e511acf628c799e168b5.tar.gz brdo-7536a354141c48c19109e511acf628c799e168b5.tar.bz2 |
#612974 by effulgentsia: Optimize toolbar to only build if it will be displayed (performance improvement).
Diffstat (limited to 'modules/toolbar')
-rw-r--r-- | modules/toolbar/toolbar.module | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/modules/toolbar/toolbar.module b/modules/toolbar/toolbar.module index 3bf85b533..9003daedc 100644 --- a/modules/toolbar/toolbar.module +++ b/modules/toolbar/toolbar.module @@ -36,10 +36,22 @@ function toolbar_theme($existing, $type, $theme, $path) { * Add admin toolbar to the page_top region automatically. */ function toolbar_page_build(&$page) { - if (user_access('access toolbar')) { - $page['page_top']['toolbar'] = toolbar_build(); - $page['page_top']['toolbar']['toolbar_drawer'] = isset($page['toolbar_drawer']) ? $page['toolbar_drawer'] : array(); - } + $page['page_top']['toolbar'] = array( + '#pre_render' => array('toolbar_pre_render'), + '#access' => user_access('access toolbar'), + 'toolbar_drawer' => isset($page['toolbar_drawer']) ? $page['toolbar_drawer'] : array(), + ); +} + +/** + * Prerender function for the toolbar. + * + * Since building the toolbar takes some time, it is done just prior to + * rendering to ensure that it is built only if it will be displayed. + */ +function toolbar_pre_render($toolbar) { + $toolbar = array_merge($toolbar, toolbar_build()); + return $toolbar; } /** @@ -85,10 +97,9 @@ function toolbar_build() { '#attributes' => array('id' => 'toolbar-menu'), ); - // Add logout & user account links - $build['toolbar_user'] = array( - '#theme' => 'links', - '#links' => array( + // Add logout & user account links or login link + if ($user->uid) { + $links = array( 'account' => array( 'title' => t('Hello <strong>@username</strong>', array('@username' => $user->name)), 'href' => 'user', @@ -98,7 +109,19 @@ function toolbar_build() { 'title' => t('Log out'), 'href' => 'user/logout', ), - ), + ); + } + else { + $links = array( + 'login' => array( + 'title' => t('Log in'), + 'href' => 'user', + ), + ); + } + $build['toolbar_user'] = array( + '#theme' => 'links', + '#links' => $links, '#attributes' => array('id' => 'toolbar-user'), ); return $build; |