Writings Photos Code Contact Resume
Drupal, The rules, Start with 3...

You are here

Submitted by msameer on Sun, 14/05/2006 - 2:27pm

Rule #1: When you create a module, Never do

<?php
function foo_menu($may_cache) {
$links = array();
 if (
$may_cache)
  {
  
$links[] = array(
                
'path' => 'foo/foo',
                
'title' => 'FOO Title',
                 
'callback' => 'foo_page',
                 
'access' => TRUE
                 
);
}
 if ((
arg(0) == 'node') && (is_numeric(arg(1)) && (user_access('administer foo'))))
{
 
$links[] = array(
          
'path' => 'node/'.arg(1).'/foo',
          
'title' => 'Foo 2',
          
'callback' => 'foo_2_page',
          
'callback arguments' => array(arg(1)),
          
'access' => user_access('administer foo'),
          
'type' => MENU_LOCAL_TASK,
    );
}
return
$links;
}
?>

Always do:

<?php
function foo_menu($may_cache) {
$links = array();
  if (
$may_cache)
    {
     
$links[] = array(
                      
'path' => 'foo/foo',
                      
'title' => 'FOO Title',
                      
'callback' => 'foo_page',
                      
'access' => TRUE
                      
);
}
else {
    if ((
arg(0) == 'node') && (is_numeric(arg(1)) && (user_access('administer foo'))))
{
    
$links[] = array(
               
'path' => 'node/'.arg(1).'/foo',
               
'title' => 'Foo 2',
               
'callback' => 'foo_2_page',
               
'callback arguments' => array(arg(1)),
               
'access' => user_access('administer foo'),
               
'type' => MENU_LOCAL_TASK,
                 );
}
}
return
$links;
}
?>

Rule #2:
NEVER EVER have a module called foo and a theme called foo, The module foo_help will be called without an argument and you'll get a warning.

Rule #3: The ultimate: Screw Amr, Drupal 4.7 is not buggy, The problem is between your keyboard and monitor.

Add new comment

Subscribe to /  digg  bookmark