Adding button to toolbar for non-admin Im trying to add a button to the toolbar for my module. Now I know I can just it in the menu and blah blah but I want it to make it when the module is activated. I think im on the right track using hook_menu however it doesn't exactly specify the callback to do this.

This is what I have so far....

function mysite_form_menu() {
$items = array();
$items['admin/config/mysite_form/ads'] = array(
    'title' =&gt; 'mysite Ad\'s',
    'description' =&gt; 'Allows administrators to adjust ads.',
    'page callback' =&gt; 'ads_page_callback',
    'access callback' =&gt; 'current_user_hide_tabs',
    'page arguments' =&gt; array('ads'),
    'access arguments' =&gt; array('administer editor mysite settings'),
    'file' =&gt; 'thank_you_ads.inc',
    'file path' =&gt; drupal_get_path('module', 'mysite_form'),
);
}
function current_user_hide_tabs() {
  global $user;

  if (isset($user-&gt;roles['3']) || isset($user-&gt;roles['5'])) :
  return true;
  else :
  return false;
  endif;

}


This is a image of the toolbar I am talking about so there is not any confusion.
The buttons on the toolbar are automatically added when the module is enabled, as long as the menu items defined from the module with hook_menu() are sub-menus of the admin menu defined from the System module.

The function that renders the toolbar is toolbar_view(), which contains the following code.

  // Retrieve the admin menu from the database.
  $links = toolbar_menu_navigation_links(toolbar_get_menu_tree());
  $build['toolbar_menu'] = array(
    '#theme' =&gt; 'links__toolbar_menu', 
    '#links' =&gt; $links, 
    '#attributes' =&gt; array('id' =&gt; 'toolbar-menu'), 
    '#heading' =&gt; array(
      'text' =&gt; t('Administrative toolbar'),
      'level' =&gt; 'h2',
      'class' =&gt; 'element-invisible',
    ),
  );


toolbar_menu_navigation_links() excludes the hidden menu items, and the ones to which the user doesn't have access.

toolbar_view() is called from toolbar_pre_render(), which is the pre-render function added from toolbar_page_build() to $page['page_top']['toolbar']. Once the module is disabled, the menu items should not be anymore visible on the toolbar. The Toolbar module doesn't use any cache; I would expect the change to be immediately visible.

To appear on the toolbar, the menu item needs to be a direct sub-menu of admin. Differently, as in your case, it will not appear in the toolbar. 

To test it, I added the following code in a module I use to test code.

/**
 * Implements hook_menu().
 */
function code_testing_menu() {
  $items['admin/mysite_form'] = array(
    'title' =&gt; 'My site form',
    'description' =&gt; 'Set custom settings for a site',
    'page callback' =&gt; 'drupal_get_form',
    'page arguments' =&gt; array('code_testing_mysite_form'),
    'access callback' =&gt; 'code_testing_mysite_access',
  );

  return $items;
}

function code_testing_mysite_form($form, &amp;$form_state) {
  $form['code_testing_switch_lights'] = array(
    '#type' =&gt; 'checkbox', 
    '#title' =&gt; t('Switch lights on.'),
    '#default_value' =&gt; variable_get('code_testing_switch_lights', TRUE),
  );

  return $form;
}

function code_testing_mysite_access() {
  return user_access('administer site');
}


What I obtained is visible in the following screenshots.





Once the module is disabled, the toolbar doesn't contain anymore the menu.



I would rather not put a menu item directly, under admin, if not in particular cases. If the menu item just shows a form for a module's settings, I would not show it in the toolbar. If, vice versa, the module would show a page of links like the Advanced help does, then I could consider adding the menu item directly under admin.

In the other cases, I would consider adding links through the Shortcut module. This would mean adding code in hook_enable() that:


Creates a new shortcut set to use for the users with a specific role
Sets the new shortcut set as default for those users


In hook_disable(), the code should:


Change back to the old shortcut set


Once the module is uninstalled, it should remove the shortcut set it created.

As alternative, the module could add a new link to the shortcut set used from user with a specific role.

The functions that such code would use are the following ones:


shortcut_default_set()
shortcut_set_save()
shortcut_set_load()
shortcut_set_assign_user()


Playing with the Shortcut module, and manually adding a link to a menu item defined in hook_menu() from a module that I then disable, I noticed the link is automatically removed from the shortcut set once the module is disabled. Even after re-enabling the module, the link is not anymore shown as part of the shortcut set.





The second screenshot shows the shortcut content after the module is disabled.

After I re-enable the module (which defines the "My site form" menu callback I shown before), this is what appears as content of the shortcut set. I didn't save the shortcut set, since the other screenshot.