1.20.x admin_bar.api.php hook_admin_bar_replacements($complete)

Return content to be replace via JS in the cached menu output.

Parameters

bool $complete: A Boolean indicating whether all available components of the menu will be output and the cache will be skipped.

Return value

array: An associative array whose keys are jQuery selectors and whose values are strings containing the replacement content.

File

modules/admin_bar/admin_bar.api.php, line 125
API documentation for Administration bar.

Code

function hook_admin_bar_replacements($complete) {
  $items = array();
  // If the complete menu is output, then it is uncached and will contain the
  // current counts already.
  if (!$complete) {
    // Check whether the users count component is enabled.
    $components = config_get('admin_bar.settings', 'components');
    if (!empty($components['admin_bar.users']) && ($user_count = admin_bar_get_user_count())) {
      // Replace the counters in the cached menu output with current counts.
      $items['.admin-bar-users a'] = $user_count;
    }
  }
  return $items;
}