Drupal 7 Menu Badges Module

By shane
Mon, 2013-02-04 00:35
2 comments
Daily Dose of Drupal Episode #101

Share with Others

The Drupal 7 Menu Badges module is a neat little module that allows you to add numbered badges next to menu items on a Drupal 7 website. It integrates nicely with views so you can easily add your own numbered icons to any menu link. You will also need the Link Badges module for this to work.

In this episode you will learn:

  • How to add a Menu Badge to a Drupal PrivateMsg link
  • How to create your own custom Menu Badge using Views and apply it to a Drupal menu link

Today's episode was sponsored by Drupalize.me

Hello everyone and welcome to another Daily Dose of Drupal, today we’re on Episode Number 101 and if you haven’t checked out episode 100 yet I suggest you do so, it’s a pretty good episode.

Today we’re going to be going over the Menu Badges Module. The Menu Badges Module is a really cool little module that allows you add this Number Identifier Badge next to Menu Links and this can be really useful for letting people know how many items are going to be displayed when they click that link so you can see in this little screen shots it shows how many messages this link will actually hold once they click on it or how many items are in the user’s shopping cart.
But before we get started; as always I am Shane Thomas, you can follow me on Twitter @smthomas3, you can also go to codekarate.com and make sure to sign up for the newsletter. Today’s sponsor is drupalize.me and if you haven’t learned or haven’t heard about drupalize.me I highly suggest them out if you’re looking to learn anything from the basics of Drupal to more complex topics on Drupal, drupalize.me is the place you should check out.

They have 674 videos and over 245 hours of Drupal training and I can tell you that it is worth your time to check out because I’ve learned a lot from dupalize.me. I was a subscriber from a long time in the past and I can thank them for a lot of what I’ve learned with Drupal and I learned a lot of the more complex things there like security and website scalability and all those things but it’s good for beginners up until potentially experts as well so go ahead and check that out and use the promo code or coupon code CK20FEB to get 20% off.

Alright let’s go ahead and get started; I have a test site here and I’ve already downloaded the Menu Badges Module and also with the Menu Badges Module you will need to download and install the link badges module but I have both of those enabled on our test site you can configure the permissions but all that it allows you to do is select who can administer the Menu Badges Module.

The first thing I’m going to do is I do have the private messages module installed, you can see a past episode of how I got that installed but basically it’s going to show … we want the little icon to show on the top right corner to say how many messages I have or how many new messages I have.

So that’s … the good thing about this is it’s already built into the module itself, the link for the Menu Badges Module so I simply come in to my user menu and I will go to the links. It says here I have one new and if I go in edit this menu it’s going to allow me to select a display menu badge and now as you can see there’s already some prepopulated in this list.

So I simply select unread count for the current user, click Save and you’ll see now I already have this little display icon or badge up in the top right corner. So I simply save this and close out and I have my little menu badge. So while that is obviously very useful there are maybe come times when you need to display it your own custom pages or custom views.

So in the past episode I created a bookmark section and I’m going to show you an example using Views so make sure you have the Views Module installed of course of how to get the little icon that show up on the top right of this My Bookmarks link inside the navigation menu. So the first thing I’m going to do I’m going to go in and I’m just going to edit this view and I’m going to add another item here and I want to select Menu Badge as the type of view and I’m going to basically take … I can give this a title if I need to but I’ll go ahead and leave that, you can leave all the rest the same, you can select the field.

Since you’re going to be aggregating these fields you can go ahead and select just the content and ID will work, unselect the label because it’s not needed, I’ll also need to select the filter criteria so I’m going to use the same filter criteria that I use over here so I need to make sure I use only publish content but I’m also going to need to set this relationships this is using the flags module.

As I mentioned before you can make sure you go and check out that module for that episode of the Daily Dose of Drupal if you haven’t already as it will allow you to see I actually got this view set up in the first place. So I’ll add the relationship which is just going to give me a relationship for that flag and I want it for the current user include only the flag content, select the bookmarks, I’m also going to need to add a content offer relationship I believe, I’ll just check one thing here.

I actually don’t believe I need that so I’m going to go ahead and take that one off and I don’t think that one is actually needed because we’re not using any fields that require that relationship. So I’ll go ahead and make sure I also select to use aggregation and this is important. If you’re familiar with SQL or making database queries this aggregation is basically going to allow you to group things so this grouping is of course going to limit the number that’s shown so it’s actually not just going to give you just the NID so if I go ahead and turn this off you’ll be able to see what’s showing down here right now is this NID.

If I group this it’s not just going to show the NID, I can come in here and select the aggregation settings and select Count. Now it’s going to say I have one item instead of just the Node ID of 3, it’s saying there’s just one item because I’m counting the number of Items.

This aggregation is similar to using a group by type claws inside of an SQL statement if you’re familiar with that and that is how that works so we’re going to give that a Save. Now we need to come into our Menu links so I’m going to come into my menus, my navigation menu, I’m going to my bookmarks and select Edit and I’m going to select display menu badge, I didn’t give it a title but if you had given a title it will be a little easier to differentiate there, I’m going to save this.

Now you can see it shows I have one item bookmark, it’s this Test Article 2, I’m going to see if I can bookmark another item. Now if I click you can see it shows I have two items now bookmarked. So that’s really how the Menu Badges Module works. There’s also another element to the Menu Badges, there’s a Tab Menu Badges and this can be used for administration pages if you created an administration page and you wanted an icon up here on the top of an administration menu tab you could use this as well.

You simply come in here and you select the item. For instance in the settings I could select this item, settings should be up here I believe but that would be the admin appearance settings but if I save it you’d notice that the item now shows up in this menu tab as well.

So you can use it not only for the front end but you can also use it for the administration pages and it’s a really handy module. I’m actually using it in a project I’m working on currently so go ahead and give it a try and let me know what you think. If you have any other suggestions for future modules you want me to review go ahead and let me know on Twitter or end me an e-mail or contact me on codekarate.com. Thanks again to drupalize.me and thank you for watching that Daily Dose of Drupal. See you next time.

Comments

Hi, can this also be setup to create a view for only "NEW" content or comments?
I tried to enable/create a view this with the Content: Has new content field, but it's not working.
Any idea on how to achieve?

Thx

Not exactly sure on this, but I don't see what it wouldn't work. Does the filter do anything to your view or does it just seem like it is not working at all. Can you provide some more information about what is and what is not working.

Post new comment