Adding contextual menu links and using menu autoloaders

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    In this final chapter about implementing Drupal's hook_menu,
  • 0:11
    we're going to take a look at 2 more things that we can do when creating new menu items.
  • 0:16
    First, we're going to take a look at how we can add a link
  • 0:20
    to the contextual links menu for all the nodes on our site.
  • 0:24
    Now the link's going to be this one where it says Magic.
  • 0:26
    When you click on it, you'll be taken to a page
  • 0:29
    that says this Sample Page has been Magicified and it shows the text of the page upside down.
  • 0:36
    In addition to adding contextual links,
  • 0:39
    we're also going to take a look at using a system
  • 0:41
    that Drupal refers to as autoloaders,

Module Development for Drupal 7

Loading ...

Adding Contextual Menu Links and Using Menu Autoloaders


This chapter walks through the process of adding links to the contextual drop-down widgets new in Drupal 7. It also shows how using menu autoloaders can help simplify the code that you write in your page callback function since you won't have to do extra checking on the data.

As a note, if you are wondering why we started our function with an underscore (_), naming functions with an underscore in front of the name is a common convention in Drupal that sort of implies that "this function is for internal use by this module only" and shouldn't be called by itself. It's also a nice way to ensure that your internal functions are not colliding with the namespace of a hook or another module. Here's a good blog post about naming things.

Log in or sign up to download companion files.
Additional resources: 

Average review

Average: 5 (2 votes)



I love how Joe starts off with using the "%" wildcard to explain the process that happens when it's called in a function and then goes step by step with what Drupal listens to and can do with it. He always focuses on important details such as documenting before he writes new code, takes the latest render able output (even showing us how to find it using Devel as an example), explains what is best practice for Drupal PHP writing, and then at the end of writing a function perfectly goes back and tells us how Drupal already provides us some defaults and then simplifies the code we were writing in the lesson and easily allows me to understand the concept of what happens in a raw "%" wildcard and a predefined Drupal "%node," "%user," %term" that is part of the "(node/term/user, etc)_load." It was essential for me to have some background on the story line for the function we were writing so thank you Joe!!!


If you use ckeditor or any other WYSIWYG HTML editor module, you have to set the text format to plain text and remove the

tags. Otherwise, those tags would be inverted and the text does not show up.
Great video!