Building out Drupal module interfaces with a stub function

A technique that I’m finding quite useful during module development is to create a “stub” function for use as a generic interface callback for menu items that I want to define, but haven’t yet written callbacks for. For example, if I were building a Drupal 5 module called widgetmaster, I would define:

function _widgetmaster_stub($message = "This feature is still
in development.") {
return '<em>'. t($message) .'</em>;
}

So if I’m planning an admin section for my module but haven’t gotten around to implementing it yet, I can at least build out the menu so I (or a client) can click around and make sure the interaction and flow makes sense… for example:

/**
* Implementation of hook_menu().
*/
function widgetmaster_menu($may_cache) {
$items = array();
$access = user_access('access administration pages');
if ($may_cache) {
$items[] = array(
'title' => t('Widgetmaster Settings'),
'path' => 'admin/settings/widgetmaster',
'callback' => '_widgetmaster_stub',
'type' => MENU_NORMAL_ITEM,
'access' => $access
);

$items[] = array(
'title' => t('Overview'),
'path' => 'admin/settings/widgetmaster/overview',
'callback' => '_widgetmaster_stub',
'type' => MENU_DEFAULT_LOCAL_TASK,
'access' => $access
);

$items[] = array(
'title' => t('Advanced'),
'path' => 'admin/settings/widgetmaster/requiredfields',
'callback' => '_widgetmaster_stub',
'type' => MENU_LOCAL_TASK,
'access' => $access
);
}

I can also leave myself specific notes as to what a particular menu callback is supposed to do:

...

$items[] = array(
'title' => t('Advanced'),
'path' => 'admin/settings/widgetmaster/requiredfields',
'callback' => '_widgetmaster_stub',
'callback arguments' => array('Select advanced options from
the widgetmaster_frob table and display as a set of
checkboxes');
'type' => MENU_LOCAL_TASK,
'access' => $access
);

...

Usage needn’t be limited to menu callbacks, either; it’s handy wherever you know you’ll eventually be defining a function that returns a string.

I’m finding it very helpful to have these stub interfaces in place early on in development. It helps fine-tune interaction, and it also serves as a contextual TODO list.

I'm Going to Use This

I'm going to use this with my drupal blog. Thank you for sharing this.

That's absolutely a

That's absolutely a brilliant post.Drupal is exactly a great module.Keep posting

my current module list

I don't want to sound like a huge nube, but this is the first explanation of the stub function that I actually understood! I have played around with a few modules:

(SEO and a zipcode redirect module - www.activelamp.com/blog/zipcode-redirect-module (hah, I had a client ask, "so I want that thing that knows where you are from... you know like those sites that know where you are from... (norp)" hahahah

I am trying integrate a business voip mod into a client's site and I'll try using Drush for the first time.

thanks for the info!

- gradyMOD

Hm, i don't get it. The hook

Hm, i don't get it. The hook menu isn't shown. But i did it excactly like it is told above. Can someone help me?

Drupal allows any module to

Drupal allows any module to register callback functions for any URI or a portion of URI. Whilst there's always room for improvement, Drupal and WordPress are both great candidates for dating service platform, they have very distinct niche areas that each should strive in and not try to compete with each other.

Thats a great technique

This will ensure no errors are return and will help in tracking a large number of menu item which still needs work.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><div> <br><img>
  • Lines and paragraphs break automatically.

More information about formatting options

Verification
This question is for testing whether you are a human visitor and to prevent automated spam submissions.