Drupal Menu Badges + Views + Flags + Rules = Counting Messages

<p>The Drupal project I'm currently working with get's complicated each and every day - so for a start I faced a problem to display dynamic content as menu items - i found a great not to say one of the greate findings this years in field of Drupal development - <a href="http://www.reinisfischer.com/drupal-create-dynamical-menus-menu-views&q…; target="_blank">Drupal &nbsp;Menu Views</a> , then I faced a problem to display tokens in Menu paths - again a superb solution with help of <a href="http://www.reinisfischer.com/menu-tokens-module-drupal-site&quot; target="_blank">Menu Tokens module</a>.</p><p>Finaly I faced another Drupal Menu related problem -<strong> to display a comment count in a Dynamical Menu with menu tokens enabled.&nbsp;</strong></p><p>I must admit - I was lucky enough to solve this problem as well - <strong>The Solution</strong> comes from another great Drupal module - Menu Badges</p><h2>About Menu Badges</h2><p><span>Provides a method for adding iOS-style badges to menu items.&nbsp;</span></p><h2>Adding Badges to Menus</h2><p>Once enabled, go to Administration &gt; Structure &gt; Menus, and click "list links" next to the menu containing the target item. Click "edit" next to the item and select the badge to display with the Display Menu Badge select box.</p><h2>Adding Badges to Tabs</h2><p>For adding badges to menu tabs, there is a tab under Administration &gt; Structure &gt; Menus called "Tab Menu Badges". Search for the menu router path of the tab you want to alter, then select a badge from the corresponding select box.</p><h2>Badge Types</h2><p>The module includes five example badges, and new badges can be created easily with&nbsp;<a href="http://drupal.org/project/views&quot; rel="nofollow">Views</a>. See this screencast for instructions:&nbsp;<a href="http://www.youtube.com/watch?v=4AoZQNg5QOI&quot; rel="nofollow">http://www.youtube.com/watch?v=4AoZQNg5QOI</a&gt;. Modules can also supply their own badges with a hook implementation. See the&nbsp;<a href="http://drupalcode.org/project/menu_badges.git/blob_plain/refs/heads/7.x…; rel="nofollow">README.txt</a>file for details.</p><p>&nbsp;</p><p>This is what I got after a couple of minutes playing with views and Menu badges</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadges.jpg&quot; alt="Menu Badges Example" title="Menu Badges Example" width="440" height="82"></p><p><em>Menu Badges Example</em></p><p>Now - as you can see from the above screen - this small element actually takes a lot views and a lot custom CSS - but it does well what it must to do.</p><p>Now the tricky part was to setup a view - which actually counts items, to be displayed on Menu Badges.</p><p>I created a view with Menu badge display counting all comments published on site (this is the behaviour customer is looking for)</p><p>To get a count out of Drupal views - we must turn on Aaggregation and add a NID field and set it to count (use aggregation)</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadgeview.jpg&quot; alt="Menu Badge View" title="Menu Badge View" width="1172" height="600"></p><p><em>Menu Badge View</em></p><p>As you can see from screen above - I'm using Flags Relationship, to count kinda only those comment's logged in user hasn't read yet (the tricky part here - I have not yet figured out how to decrease counter).&nbsp;</p><p>Flags are created by using another module: Drupal Flags.&nbsp;</p><p>Nothing fancy there - download that module, create a new comment type flag (is_new), now to get things more complexed you will have to add Drupal Rules (again, there is Drupal Rules module, you can use).</p><p>I created a new rule - which basically does following - <strong>after comment is saved it's flagged as is_new</strong> (so I can use this flag in my views)</p><p>What I haven't yet figured out is how to create a rule, which removes flag <strong>is_new</strong> after user has viewed particular comment.</p><p>Anyway - we have fully functional views, flags and we have menu badges module.</p><p>What we do now - we go to our Menus and add a menu badge to links - menu badges are created from view we made before</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadgeslink.jpg&quot; alt="Menu badges link" title="Menu badges link" width="1200" height="352"></p><p><em>Menu badges link</em></p><p>That's all - you can use CSS to style your badge icon.</p><p>P.S. If you have some idea how I can create a Drupal rule, to remove is_new flag after comment has been viewed - please drop me a comment!</p>