From ec1d8fad4f4e3e3171ba85f7342f536334d2933d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?"J.=20Rene=CC=81e=20Beach"?= Date: Fri, 14 Dec 2012 17:20:28 -0500 Subject: [PATCH] removed the hook_toolbar_alter call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: J. ReneĢe Beach --- toolbar_example.module | 86 ++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/toolbar_example.module b/toolbar_example.module index df4facc..2e31b99 100644 --- a/toolbar_example.module +++ b/toolbar_example.module @@ -2,24 +2,26 @@ /** * @file - * A module to illustrate API interaction with the Toolbar module. + * A module to illustrate API interaction with the toolbar module. * * The responsive toolbar will display at the top of every page if the current * user has the "access toolbar" permission. * + * Modules can add to the toolbar by implementing hook_toolbar(). A module may + * pass any renderable content to the toolbar. + * * Elements of the toolbar can be anything, but normally they are links. If - * there is a corresponding "tray", then it will display when the tab is - * activated. If not, or if javascript is disabled, then the tab will function - * as an ordinary link. + * there is a corresponding "tray", then it will display when the its + * associated tab is activated. If not, or if javascript is disabled, then the + * tab will function as an ordinary link. * * The tray can also be anything, but a list of links is common. * - * Modules can add to the toolbar by implementing hook_toolbar(), as below. - * Return an array. Most modules will add only one new tab, and will normally - * use the module's name as the key. This example is unusual, and defines - * several new tabs and trays. The value corresponding to each key is itself an + * Most modules will add only one new tab and will normally use the module's + * name as the key. + + * he value corresponding to each key is itself an * array, with the following keys: - * - 'tab': a renderable array; if '#type' is ommitted, it defaults to 'link'. * - 'tray': a renderable array, displayed when the corresponding tab is * selected (optional). * - 'weight': an integer used in sorting (optional). @@ -49,6 +51,24 @@ function toolbar_example_toolbar() { $items = array(); +$items['user_messages'] = array( + // Include the toolbar_tab_wrapper to style the link like a toolbar tab. + // Exclude the theme wrapper if custom styling is desired. + "#type" => 'toolbar_item', + '#theme_wrappers' => array(), + '#text' => t('Messages'), + '#path' => '/user/messages', + '#options' => array( + 'html' => FALSE, + 'attributes' => array( + 'title' => t('Messages'), + ), + ), + 'tray' => array('#type' => 'search'), + '#weight' => 125, + ); + + // The simplest case is adding a simple link to the tabs. By default, '#type' // will be set to 'link'. $items['toolbar_example_link'] = array( @@ -99,24 +119,27 @@ function toolbar_example_toolbar() { // In case javascript is disabled, the link goes to a page that contains the // same form. The tab will be redefined by hook_toolbar_alter() below. $items['toolbar_example_count'] = array( - '#type' => 'toolbar_item', - '#text' => t('How many?'), - '#path' => 'toolbar_example/count', - '#options' => array( - 'attributes' => array( - 'title' => t('What is your favorite number?'), + '#theme' => 'item_list', + '#items' => array( + l(0, 'toolbar_example/count/0'), + l(1, 'toolbar_example/count/1'), + l(2, 'toolbar_example/count/2'), + 'many' => array( + '#type' => 'toolbar_item', + '#text' => t('How many?'), + '#path' => 'toolbar_example/count', + '#options' => array( + 'attributes' => array( + 'title' => t('What is your favorite number?'), + ), + ), + 'tray' => array( + '#type' => 'form', + 'element' => drupal_get_form('toolbar_example_count_form'), + ), ), ), ); - // The tray will display a simple form. - $items['toolbar_example_count']['tray'] = array( - '#type' => 'form', - 'element' => drupal_get_form('toolbar_example_count_form'), - ); - - // Functionally, this is completely redundant, but for sake of example, add a - // form directly to the tabs section. - $items['toolbar_example_form']= $items['toolbar_example_count']['tray']; return $items; } @@ -132,21 +155,6 @@ function toolbar_example_toolbar_alter(&$toolbar_groups) { if (array_key_exists('user', $toolbar_groups) && array_key_exists('home', $toolbar_groups)) { $toolbar_groups['user']['#weight'] = $toolbar_groups['home']['#weight'] = -20; } - - // Replace the "How many?" tab with three links; the third will open the tray. - // The path toolbar_example/count/% has not yet been implemented. - $many = $toolbar_groups['toolbar_example_count']; - $many['#title'] = t('Many'); - $choices = array( - l(0, 'toolbar_example/count/0'), - l(1, 'toolbar_example/count/1'), - l(2, 'toolbar_example/count/2'), - $many, - ); - $toolbar_groups['toolbar_example_count']['tab'] = array( - '#theme' => 'item_list', - '#items' => $choices, - ); } /** -- 1.7.10.4