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.

Comment viewing options

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

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.

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.

Wordpress api allows...

Doesnt wordpress already have these functionalities?

This will ensure no errors

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

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.