menu_link_view_count
Allows site builders to add dynamic count indicators to menu links using Views. Configure each menu item to display the current result count from a selected View display.
Common use cases:
- Unread messages (12)
- Pending approvals (3)
- My tasks (7)
- Any menu link that should reflect a Views-driven “queue” or “inbox” style count
Installation/Configuration
1. Enable the module.
2. Add/edit a menu link
3. In the "View count" section select the View and display you want counted. Optionally set count limit (to cap at 99+, for example).
4. Save the menu link.
5. The menu will render the link title with an appended count indicator.
Views Setup
Be advised that some pagers do not provide the full count of rows from the view, which will also apply to the count that appears in the menu link.
For the pager, use either:
- If you're planning to use a "count limit" on the menu item, use Display a specified number of items configured to limit to a value higher than the "count limit" expected to be on the menu item.
- If you're not planning to use a "count limit" on the menu item, use Display all items. For performance considerations, it's recommended to keep this View as "basic" (as few columns, etc.) as possible.
Performance
Menu items with a count applied to them are subject to caching per the View's cache handling. This can cause frequent invalidation of the caching for menus and regions where you're displaying the menus based on the configuration of the view's caching.
One module to consider to mitigate possible performance concerns is Views Custom Cache Tags.
Customization
To customize styling, override CSS in your theme targeting:
ul.menu li.has-count > aul.menu li.has-count > a .count
To customize markup/behavior, hook_menu_link_view_count_alter() in a custom module (or theme) to adjust rendering, classes, count math, or cache/attachments.
Additional Requirements
Views (Drupal core) is required.