You are here

README.txt in Menu Badges 8

Same filename and directory in other branches
  1. 7 README.txt
Provides a method for adding iOS-style badges to menu items. Once enabled, 
go to Administration > Structure > Menus, and click "list links" next to 
the menu containing the target item. Click "edit" next to the item and 
select the badge type to display with the Display Menu Badge select box. 
Currently, there are five badge types available:

 * a test badge (just says "test")
 * a count of unread messages from the PrivateMsg module. 
 * a count of items in the Drupal Commerce shopping cart.
 * a count of pending incoming requests from the User Relationships module
 * a count of pending outgoing requests from the User Relationships module 
 
I will be adding more badge types in the future, and modules can supply 
their own badge types.

As of version 7.x-1.2, you can now create badge types with Views. See this 
screencast for instructions: http://www.youtube.com/watch?v=4AoZQNg5QOI

Developer API
To provide new badges to this module, declare your callback functions by 
implementing hook_menu_badges_options. For example:

function example_menu_badges_options() {
  return array(
    'example_get_unread_count_1' => array(
      'callback' => 'example_get_unread_count',
      'arguments' => array('role' => 'parent', 'relationship_type_id' => 1),
      'label' => t('An example menu badge'),
      'module' => 'example_module',
    ),
    'example_get_unread_count_2' => array(
      'callback' => 'example_get_unread_count',
      'arguments' => array('role' => 'child', 'relationship_type_id' => 1),
      'label' => t('An second example menu badge'),
      'module' => 'example_module',
    ),
  );
}

function example_get_unread_count($arguments) {
  $path = $arguments['path'];
  // Some logic goes here.
  if ($value > 0) {
    return $value;
  }
  return NULL;
}

Note: To hide the badge, it's important to return NULL from your callback 
function. Any other return value will be displayed. (including "false" 
values, so 0 will be displayed) Badges do not have to be numeric. Text 
will also work.

File

README.txt
View source
  1. Provides a method for adding iOS-style badges to menu items. Once enabled,
  2. go to Administration > Structure > Menus, and click "list links" next to
  3. the menu containing the target item. Click "edit" next to the item and
  4. select the badge type to display with the Display Menu Badge select box.
  5. Currently, there are five badge types available:
  6. * a test badge (just says "test")
  7. * a count of unread messages from the PrivateMsg module.
  8. * a count of items in the Drupal Commerce shopping cart.
  9. * a count of pending incoming requests from the User Relationships module
  10. * a count of pending outgoing requests from the User Relationships module
  11. I will be adding more badge types in the future, and modules can supply
  12. their own badge types.
  13. As of version 7.x-1.2, you can now create badge types with Views. See this
  14. screencast for instructions: http://www.youtube.com/watch?v=4AoZQNg5QOI
  15. Developer API
  16. To provide new badges to this module, declare your callback functions by
  17. implementing hook_menu_badges_options. For example:
  18. function example_menu_badges_options() {
  19. return array(
  20. 'example_get_unread_count_1' => array(
  21. 'callback' => 'example_get_unread_count',
  22. 'arguments' => array('role' => 'parent', 'relationship_type_id' => 1),
  23. 'label' => t('An example menu badge'),
  24. 'module' => 'example_module',
  25. ),
  26. 'example_get_unread_count_2' => array(
  27. 'callback' => 'example_get_unread_count',
  28. 'arguments' => array('role' => 'child', 'relationship_type_id' => 1),
  29. 'label' => t('An second example menu badge'),
  30. 'module' => 'example_module',
  31. ),
  32. );
  33. }
  34. function example_get_unread_count($arguments) {
  35. $path = $arguments['path'];
  36. // Some logic goes here.
  37. if ($value > 0) {
  38. return $value;
  39. }
  40. return NULL;
  41. }
  42. Note: To hide the badge, it's important to return NULL from your callback
  43. function. Any other return value will be displayed. (including "false"
  44. values, so 0 will be displayed) Badges do not have to be numeric. Text
  45. will also work.