Drupal 6.x hook_menu question regarding use of wildcards
I'm trying to figure out if I can use wildcards in this manner: <?php $items['node/agenda/list/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(3), 'page callback' => 'agenda_list', 'page arguments' => array(3)->nid, 'access callback' => 'user_access', 'access arguments' => array('view agenda'), 'type' => MENU_CALLBACK ); ?> Since array(3) represents node_load(arg(3)), can I use the statement array(3)->nid for the node id. Or, for that matter, array(3)->type for the node type? If not, what's the correct way? Would it be the old fashioned way (i.e., page arguments' => arg(3))? Thanks for any assistance. -ron -- Ron Parker Software Creations http://www.scbbs.com Self-Administration Web Site http://saw.scbbs.com SDSS Subscription Mgmt Service http://sdss.scbbs.com Central Ave Dance Ensemble http://www.centralavedance.com R & B Salsa http://www.randbsalsa.com
Um, array(3)->nid is not valid PHP syntax. Is that what you really meant? On Fri, Feb 15, 2008 at 9:35 AM, Ron Parker <sysop@scbbs.com> wrote:
I'm trying to figure out if I can use wildcards in this manner:
<?php $items['node/agenda/list/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(3), 'page callback' => 'agenda_list', 'page arguments' => array(3)->nid, 'access callback' => 'user_access', 'access arguments' => array('view agenda'), 'type' => MENU_CALLBACK ); ?> Since array(3) represents node_load(arg(3)), can I use the statement array(3)->nid for the node id. Or, for that matter, array(3)->type for the node type?
Chris Johnson wrote:
Um, array(3)->nid is not valid PHP syntax. Is that what you really meant?
That's my question. I'm trying to figure out if the wildcard value can be used in such a way. In my example, the wildcard is %node, which is equal to ($node = node_load(arg(3)). array(3) is now equal to $node. So, is there a way to write the equivalant of $node->nid or $node->title?
On Fri, Feb 15, 2008 at 9:35 AM, Ron Parker <sysop@scbbs.com> wrote:
I'm trying to figure out if I can use wildcards in this manner:
<?php $items['node/agenda/list/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(3), 'page callback' => 'agenda_list', 'page arguments' => array(3)->nid, 'access callback' => 'user_access', 'access arguments' => array('view agenda'), 'type' => MENU_CALLBACK ); ?> Since array(3) represents node_load(arg(3)), can I use the statement array(3)->nid for the node id. Or, for that matter, array(3)->type for the node type?
__________ NOD32 2879 (20080215) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
-- Ron Parker Software Creations http://www.scbbs.com Self-Administration Web Site http://saw.scbbs.com SDSS Subscription Mgmt Service http://sdss.scbbs.com Central Ave Dance Ensemble http://www.centralavedance.com R & B Salsa http://www.randbsalsa.com
On Friday, 15. February 2008, Ron Parker wrote:
Chris Johnson wrote:
Um, array(3)->nid is not valid PHP syntax. Is that what you really meant?
That's my question. I'm trying to figure out if the wildcard value can be used in such a way. In my example, the wildcard is %node, which is equal to ($node = node_load(arg(3)). array(3) is now equal to $node.
No, array(3) is equal to (in print_r() syntax) Array ( [0] => 3 ) and the menu system just uses this standard PHP array as callback argument in order to get the real number (and from that, the node itself). I mean, don't get me wrong - I understand your point, just make sure you recognize that this isn't any special node system syntax but standard PHP. wishes, jakob
Yes, thank you. That answers my question. I had to re-think my approach. For others who stumble with this as I have, the solution is to write your own callbacks customized to process the wildcard value and return the value you want. That's what I did below with 'agenda_page_title' and '_agenda_list': <?php function agenda_menu() { $items = array(); $items['node/agenda/list/%node'] = array( 'title callback' => 'agenda_page_title', 'title arguments' => array(3, 'List agenda items for: '), 'page callback' => '_agenda_list', 'page arguments' => array(3), 'access callback' => 'user_access', 'access arguments' => array('view agenda'), 'type' => MENU_CALLBACK ); return $items; } function _agenda_list($node) { return agenda_list($node->nid); } function agenda_page_title($node, $text) { $return = $text . $node->title; return $return; } ?> Jakob Petsovits wrote:
On Friday, 15. February 2008, Ron Parker wrote:
Chris Johnson wrote:
Um, array(3)->nid is not valid PHP syntax. Is that what you really meant?
That's my question. I'm trying to figure out if the wildcard value can be used in such a way. In my example, the wildcard is %node, which is equal to ($node = node_load(arg(3)). array(3) is now equal to $node.
No, array(3) is equal to (in print_r() syntax)
Array ( [0] => 3 )
and the menu system just uses this standard PHP array as callback argument in order to get the real number (and from that, the node itself). I mean, don't get me wrong - I understand your point, just make sure you recognize that this isn't any special node system syntax but standard PHP.
wishes, jakob
__________ NOD32 2880 (20080215) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
-- Ron Parker Software Creations http://www.scbbs.com Self-Administration Web Site http://saw.scbbs.com SDSS Subscription Mgmt Service http://sdss.scbbs.com Central Ave Dance Ensemble http://www.centralavedance.com R & B Salsa http://www.randbsalsa.com
<?php function _agenda_list($node) { return agenda_list($node->nid); } ?> why not make agenda_list accept a $node instead of a nid and change inside? Why a whole wrapper? <?php function agenda_page_title($node, $text) { $return = $text . $node->title; return $return; } ?> Welcome to the wonderful word of XSS holes!!!!! You want check_plain($node->title) and likely check_plain ($text . $node->title)
<?php function agenda_page_title($node, $text) { $return = $text . $node->title; return $return; } ?>
Welcome to the wonderful word of XSS holes!!!!! You want check_plain($node->title) and likely check_plain ($text . $node->title)
Actually not. drupal_get_title runs a check_plain on the menu_get_active_title() . I only checked menu.inc . Sorry! I will update the handbook to indicate this.
'page arguments' => array(3)->nid, Sorry. You need to take the node. There is not really another way. I believe that's not that big of a problem -- take the node as argument and use $node->nid in place. If you really really need the nid then use %node_nid and then a) node_nid_load does a node_load and returns the nid b) need an access callback which takes a nid , loads it again (yeah...) and calls node_access on that. Regards, NK
participants (4)
-
Chris Johnson -
Jakob Petsovits -
Karoly Negyesi -
Ron Parker