function quickbar_available in Quickbar 7
Same name and namespace in other branches
- 7.2 quickbar.module \quickbar_available()
Helper for returning whether a quickbar toolbar should be displayed based on uid and settings.
2 calls to quickbar_available()
- quickbar_page_build in ./
quickbar.module - Implements hook_page_build()
- quickbar_preprocess_html in ./
quickbar.module - Implements hook_preprocess_html().
File
- ./
quickbar.module, line 254
Code
function quickbar_available() {
if (quickbar_is_enabled()) {
// Declare initial variables.
global $user;
// Need a serialized array for default value.
$role_weights = variable_get('quickbar_role_weights', array());
if (is_array($role_weights)) {
// Sort roles
asort($role_weights);
// Set some variables we might need.
$roles = user_roles();
$use_machine_names = variable_get('quickbar_use_machine_names', 0);
if ($use_machine_names) {
$machine_roles = _quickbar_role_machine_names($roles);
}
// Loop through the roles looking for a role that matches the current users
// role and also has a menu associated with it.
$menus = variable_get('quickbar_role_menus', array());
foreach ($role_weights as $rid => $weight) {
if (isset($menus[$rid])) {
$menu = $menus[$rid];
$user_role_index = $use_machine_names ? array_search($machine_roles[$rid], $roles) : $rid;
if (!empty($user->roles[$user_role_index]) && $menu) {
return array(
'rid' => $rid,
'menu' => $menu,
);
}
}
}
}
}
return FALSE;
}