I m trying to create a new section in Administer to display my module settings, however for some reason it doesn't display.


/**
 * Implementation of hook_menu().
 */
function annotate_menu()
{
	$items = array();

	$items['admin/annotate'] = array(
		'title' => 'Node annotation',
		'description' => 'Adjust node annotation options',
		'position' => 'right',
		'weight' => -5,
		'page callback' => 'system_admin_menu_block_page',
		'access arguments' => array('administer site configuration'),
		'access callback' => 'user_access'
		);
	$items['admin/annotate/settings'] = array(
		'title' => 'Annotation settings',
		'description' => 'Change how annotations behave.',
		'page callback' => 'annotate_admin_settings',
		'access arguments' => array('administer site configuration'),
		'access callback' => 'user_access'
		);
	
	return $items;
}

This is an example from the book and its written using 5.x code. I suspect the problem is in 'system_admin_menu_block_page', although I can't find how to solve it. Could someone please point out how this code can be fixed.

Thanks in advance
What am I doing wrong?

Comments

vm’s picture

If it's 5.x code from a book and you haven't changed it for Drupal 6.x you may want to see http://drupal.org/update/modules

it will have to be updated from 5.x to 6.x and then from 6.x to 6.2 in some cases.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

sneg_’s picture

I have looked through that section but unfortunately I couldn't find a solution. I got it all to 6.x from chapter 1 but in chapter 2 authors decided to add a new section to Administer panel and it broke again. If you know what can be possibly causing this I would appreciate your help.

The $image['admin/annotate/settings'] works perfectly. Its just the first $image['admin/annotate'] which doesn't.

vm’s picture

I've not committed to 6.x yet, sorry.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

sneg_’s picture

Maybe I made a mistake downloading version 6. Its been very tough porting all this example code on-the-go, when my acquaintance with Drupal is about 2 days long.

sneg_’s picture

Thanks to someone called jmorahan_work on #drupal I managed to solve the problem. In Drupal 6 if you include stuff from other modules, you have to include the information about the file, which holds the function.

So in my case the code above becomes:

    //some code here ...
    $items['admin/annotate'] = array(
        'title' => 'Node annotation',
        'description' => 'Adjust node annotation options',
        'position' => 'right',
        'weight' => -5,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('administer site configuration'),
        'access callback' => 'user_access',
        // ADD information about where the function resides
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system')       
        );
    //some code there ...
mightypile’s picture

I've been working from the same book, Apress Pro Drupal Development, to build a module in 6.2, noting that everything in the book is 5.x. It's still fun to see "my" code come to life, but it's a lot of work figuring out how to port this stuff.

I have the same problem with these menus. I can't even find the 'file' and 'file path' options in the API documentation. Before adding the file options, I was getting an error at the top of the /admin page, after adding them, I get no error. So I know the file part fixes something. But I still get nothing when I click the link (links as expected to /admin/annotate). "Nothing" means a blank white page with no header or footer or sidebars or anything. I'm betting my problem is system_admin_menu_block_page, like you were earlier. But I'm having a hell of a time figuring out what's wrong.

From the core user module's user_menu function, the closest thing I could find to ours:

//...
  $items['admin/user'] = array(
    'title' => 'User management',
    'description' => "Manage your site's users, groups and access to site features.",
    'position' => 'left',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );
//...
  $items['admin/user/settings'] = array(
    'title' => 'User settings',
    'description' => 'Configure default behavior of users, including registration requirements, e-mails, and user pictures.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_admin_settings'),
    'access arguments' => array('administer users'),
    'file' => 'user.admin.inc',
  );
//...

It certainly seems to work fine. Mine looks similar in what look like all the right ways, but still doesn't work somehow. I still get a blank page at /admin/annotate and

"warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'system_admin_menu_block_page' was given in /var/www/includes/menu.inc on line 346."

at the top of /admin/annotate/settings.

Thanks for the info you shared so far. If I get it working, I'll post more.

-Mike

FelixSharples’s picture

I'm running Drupal 6.4 (most recent at time of writing) and had these problems while attempting to port the code in the book, and just as you did, I also got the blank screen on navigating to the page http://localhost/admin/annotate with http://localhost/admin/annotate/settings working correctly.

I did some digging into the Drupal code and the databases and I realised that for admin/annotate, the customized field in the menu_links table was set to '1', whereas other similar pages in the Administer section were not.

I hacked around it by adding 'customized' => 0, in addition to the 'file' and 'file path' fields mentioned in other replies, to the $items['admin/annotate'] item as in the following code.

function annotate_menu() {
    $items = array();
    
    $items['admin/annotate'] = array(
        'title' => 'Node annotation',
        'description' => 'Adjust node annotation options',
        'position' => 'right',
        'weight' => -5,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('administer site configuration'),
        'access callback' => 'user_access',
        // Added the following three lines to fix the problem of this menu item/link not working correctly in Drupal 6.
        // The setting of 'customized' is a hack!
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system'),
        'customized' => 0,
        );
    $items['admin/annotate/settings'] = array(
        'title' => 'Annotation settings',
        'description' => 'Change how annotations behave.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array( 'annotate_admin_settings' ),
        'access arguments' => array('administer site configuration'),
        'access callback' => 'user_access',
        );
   
    return $items;
}

I've trawled the code and I just don't know it well enough to identify why customized is being set to 1, but the Drupal developers might be able to shed some light on the matter? I'm certainly intrigued as to why this is, and why others areas seem to work fine (I compared this menu setup with others in the Drupal source but that didn't provide any answers) but this doesn't without the hack.

A question I would ask to the more experienced Drupal developers would be: are the 'file' and 'file path' fields documented anywhere? Like mightypile I can't find them in the API docs and, without wanting to sound rude, I have to say it would be disappointing if fields that are evidently required aren't properly documented anywhere. (Apologies if I've missed them.)

vm’s picture

have you compared the book code to the annotate.module that was uploaded into the repo ? see: http://drupal.org/project/annotate not sure if its the same or not, but at one time I thought it was.

I don't know which version of the book you are using, but I do seem to recall at least one typo in the book with regards to the annotate.module that was corrected in the errata information collected on the website.

FelixSharples’s picture

Thanks for the link.

I'm using the version that develops against Drupal 5 - I think I need to go out and buy the 2nd edition ;)

Looking at the 6.x.1-dev source it is placing the settings form at admin/settings/annotate, not admin/annotate/settings. The former ports fine. It is the latter that I - and others - have been trying to get working with Drupal 6. (The books suggests giving the module its own settings category in Administer as a contrived example - page 24 section Defining Your Own Administration Section.)

Update:

Bizarrely I've just returned to this problem and it now works on my machine without the hack and the rows in menu_links are being set up correctly. Very strange because it definitely had problems the other day and I haven't reset my PC or restarted the server. (I have only progressed to the end of chapter 3 since, only adding a couple of extra items to the admin settings form.)

I now think that the 'customized' field aspect is a red herring of a sort. As was maybe the other issue I forgot to mention(!) where the 'router_path' field was set to just 'admin' instead of 'admin/annotate'. (This caused the error Fatal error: Unsupported operand types in D:\Server\public_html\modules\system\system.module on line 635 due to no rows being returned by the db_query on that line.) I don't know how that happened and I've been unable to replicate it. The original poster may want to check the following in the database

mysql> select link_path, router_path, customized from menu_links where link_path like '%annotate%';
+-------------------------+-------------------------+------------+
| link_path               | router_path             | customized |
+-------------------------+-------------------------+------------+
| admin/annotate          | admin/annotate          |          0 |
| admin/annotate/settings | admin/annotate/settings |          0 |
+-------------------------+-------------------------+------------+
2 rows in set (0.00 sec)

mysql>

and maybe delete the rows if the data isn't as shown here. (I don't know if this will help but it's worth looking at.)

mysql> delete from menu_links where link_path like '%annotate%';
Query OK, 2 rows affected (0.03 sec)

mysql>

My hunch is that there was some inconsistency introduced during the process of relocating the settings page and adding a parent, while following along with the book (perhaps running things too early when all required parts weren't in place?) I have so far been unable to replicate it.

Perplexing...

Also:

For others looking for these, I found 'file' and 'file path' in the docs here and here. (I'd say these need to be added here though; even though it seems obvious after the fact, the second linked page isn't the first place many people will look.)

rgchi’s picture

Just wanted to say thanks to all of these posts. Here a few years later, you helped me solve a problem and learn something new along the way.