I'm just beginning to learn Drupal with that book, however, I'm no PHP expert and I'm finding it hard to comprehend... for example in Ch. 2: annotate.module:

/** 
 * Implementation of hook_menu(). 
 */ 
function annotate_menu($may_cache) { 
  $items = array(); 
  if ($may_cache) { 
    $items[] = array( 
      'path' => 'admin/settings/annotate', 
      'title' => t('Annotation settings'), 
      'description' => t('Change how annotations behave.'), 
      'callback' => 'drupal_get_form', 
      'callback arguments' => array('annotate_admin_settings'), 
      'access' => user_access('administer site configuration') 
    ); 
  } 
  return $items; 
} 

/** 
 * Define the settings form. 
 */ 
function annotate_admin_settings() { 
  $form['annotate_nodetypes'] = array( 
    '#type' => 'checkboxes', 
    '#title' => t('Users may annotate these node types'), 
    '#options' => node_get_types('names'), 
    '#default_value' => variable_get('annotate_nodetypes', array('story')), 
    '#description' => t('A text field will be available on these node types to make user-specific notes.'), 
  ); 
  $form['array_filter'] = array('#type' => 'hidden'); 
  return system_settings_form($form); 
} 

So... the annotate_menu function returns the variable $items, which is an array, we're manually assigning the 'path', 'title' and 'description'... ok... but then 'callback' => 'drupal_get_form', 'callback arguments' => array('annotate_admin_settings'), 'access' => user_access('administer site configuration')... ... WTF? I'm lost.

So... I guess the book isn't explaining everything for me, where is a good place for me to look things up?

For a total beginner, what are some general good places to look at along with the Pro Drupal Dev book?

Thank you!

Comments

gpk’s picture

1. It might be worth getting a PHP textbook. Probably *not* one of those ones with 1,001 example PHP/MySQL projects but one that gives a thorough overview of the language constructs and features. http://php.net is of course the main resource for looking up functions and the like.

2. As the book says on p. 13, "Don't worry too much about the details at this point." By the end of about Ch. 4 you should have more of a feel for what is going on here.

3. http://api.drupal.org is indispensable. For example, a function named module-name_menu() is an implementation of hook_menu() (don't worry about the $may_cache thing for now ... it's a bit confusing at the best of times!).

4. If you are impatient: drupal_get_form() is the function that will be called when you visit path admin/settings/annotate. The string 'annotate_admin_settings' is passed to drupal_get_form() as the single argument. This is actually another function - a special one that returns a form definition for a system settings form. 'access' defines the permissions for this path. Function user_access('activity') determines if the current user has permission to do 'activity'. So this menu item definition tells the Drupal to do the following when the user visits path admin/settings/annotate: check if the current user has permission to administer site configuration (if not, will get access denied message), and if so, display the annotate module's admin settings form, as defined by function annotate_admin_settings().

Enjoy!

gpk
----
www.alexoria.co.uk

dvkd’s picture

Hi gpk,
I need a help, Even i am a beginer in drupal, I followed these textbook code, but i am getting warning message like ,one argument missing for annotate_menu(),
so i removed $may_cache in annotate_menu and in if(),

And i could get the Annotate Settings in the Site configuration,
but when i tried clicking the 'Annotate Settings' , its not proceeding further,

Please help me

gpk’s picture

That code is for Drupal 5. The "signature" of hook_menu() has changed in Drupal 6 - there is no $may_cache argument any more (as you have discovered, and as you can see here http://api.drupal.org/api/function/hook_menu/6).

The menu is cached by Drupal, so to get your changes to take effect you need to clear the Caches: Admin -> Site config -> Performance.

HTH.