views:

35

answers:

2

Hello

I'm looking for some beginners resources for drupal. I've been writing my own module as a way of teaching myself the basics of development as I like the idea of having Drupal to go to when Wordpress can't manage. (Although wordpress is fast becoming as accomplished as Drupal, but that's not what the questions about.)

I have the module showing up in the enable/disable screen and the module.install file works a treat. What I'm stuck on is generating an admin area to edit entries in the table I'm using. I have a module_admin_settings() function in module.admin.inc, plus module.menu () in module.module.

But it isn't appearing in the menus and I'm stumped as to why that is. So I'm hoping someone knows a good tutorial that explains how to generate admin options.

A: 

http://drupal.org/node/206761 is what I use as a starting point.

+2  A: 

If you want to become serious with Drupal development, I would advice you to go through the Pro Drupal developemnt book. It has been the single most helpful Drupal book I have ever read.

As for your question, to create a admin section is not much different from creating a view some where. What you need to do is.

  1. Implement hook_menu to register the url you want to use, in your case admin/settings/name should be fine
  2. Implement a call back function that should be called when a user go to the your. In your case you don't need to implement one as you should use drupal_get_form, but instead you need to create the form that the user should see using the form API.

    You need to place this info in your hook_menu like this:

    function modulename_menu() {
      $items = array();
      $items['admin/settings/modulename'] = array(
        'title' => 'Menu item',
        'description' => 'The description of the menu item. It is used as title attribute and on the administration overview page.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('form_id'),
        'access arguments' => array('administer modulename'), // access restriction to admins only
      );
      return $items;
    }
    
  3. Then you need to implement validation and submit handlers for your form, is you use a system_settings_form, you can get a lot of the work done for you.

  4. Whenever you make changes to hook_menu, you need to clear the (menu) cache, as Drupal caches this information to optimize performance.

That's it. Now you don't need to use different files in your module. If the module is small all could just go into the .module file. But for bigger modules, you can place some of your code in .inc files to organize your code a bit. Fx modulename.admin.inc for your admin callbacks/functions, modulename.page.inc for your regular callback/functions etc.

googletorp
That's the book I have. It's just that I'm not quite following what it wants me to do.
YsoL8
There's complete code example for every chapter that you can just copy and use, when you read through the book. What is it you don't understand.
googletorp

related questions