[development] Advice on a menucallback
Chris McGinlay
chris at ascentsoftware.org.uk
Wed Jul 11 23:24:26 UTC 2007
Hi,
I'm trying to get a very small module running - I have a menu callback which
generates a blank page on activating the callback. I'm basing this heavily on
the onthisdate exemplar module on the drupal.org
I point my browser at ?q=list_creative/T and receive an empty page. Can
anyone advise me on what I'm doing wrong? Apologies if this should have been
posted to support instead of development.
Cheers
Chris
There is content in the database matching the T (see below).
Here is the (tiny) module:
<?php
/* $Id$ */
/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function rockstanza_help($section='') {
$output = '';
switch ($section) {
case "admin/help#rockstanza":
$output = '<p>'. t("Manages blocks for accessing creative and excursion
posts on RockStanza website") . '</p>';
break;
}
return $output;
} //function rockstanza_help
/**
* Valid permissions for this module
* @return array An array of valid permissions for the rockstanza module
*/
function rockstanza_perm() {
return array('access rockstanza content');
} //function rockstanza_perm
/**
* Implementation of hook_menu().
*/
function rockstanza_menu() {
$items = array();
$items[] = array(
'path' => 'list_creative',
'title' => t('Creative works'),
'callback' => 'rockstanza_list_creative',
'access' => user_access('access rockstanza content'),
'type' => MENU_CALLBACK
);
return $items;
}
/**
* Generate HTML for the rockstanza block
* @param op the operation from the URL
* @param delta offset
* @returns block HTML
*/
function rockstanza_block($op='list', $delta=0) {
switch ($op) {
case "list":
//listing of blocks, eg. on admin/block page
$block[0]["info"] = t("RockStanza Creative");
break;
case "view":
$block['subject'] = t('Creative works');
$block['content'] = '';
$first_letter_list = ""; //this will be a list of the first letter of
broch names
$result = db_query("SELECT title FROM {node} " .
"WHERE {node}.{type} = 'poem' ORDER BY {title} ASC");
$index = array();
do {
$t = db_fetch_array($result);
$letter=$t['title'][0];
$index[$letter]=$letter; //store unique first letters in list
} while ($t);
$letterlist = implode ('',$index); //store in variables table
foreach ($index as $fl) {
$block['content'] .= l($fl,"list_creative/$fl",
array('title' => "Creative works beginning $fl", 'target' => '_self'),
NULL, NULL, FALSE, FALSE) . ' ';
}
break;
}
return $block;
} //function rockstanza_block
/** Group creative posts (e.g. poems) by the first letter of their title
* use via menu callback
* @returns content HTML
*/
function rockstanza_list_creative($firstletter) {
$fl = '^'.$firstletter[0];
//get all poems with chosen first letter of title
$result = db_query(db_rewrite_sql(
"SELECT n.nid, n.title, n.type " .
"FROM {node} n " .
"WHERE n.type = 'poem' " .
"AND n.title REGEXP '%s' " .
"ORDER BY n.title ASC", $fl
));
//leave only the node titles in the results
$content = node_title_list($result);
}
More information about the development
mailing list