I'm not finding this is the docs...
I want to have my module declare a menu item that points to an existing node or view (this is a hack - see below for explainer), but I can't figure out what to use for the callback argument. For example:
<?php
$items['admin/content/my-dynamic-content-admin-screen'] = array(
'page callback' => '??????', // what goes here to display a node or view?
'page arguments' => ,
'title' => 'My Custom admin menu',
);
?>
Explainer:
The use-case here is that I want to be able to add links to the menu generated by the admin_menu module, which doesn't pick up user-generated links (it does pick up module-generated menu items, which is why I want to do the above - I want to be able to add links to items generated by other modules - mostly views).
Flame-avoidance notes:
* I'm concerned this may be a violation of best practices in that it would create unnecessary entries in the menu_router table, but I need the functionality and am willing to compromise my purity. If there's a better way to get what I need (short of patching admin_menu, which is not a realistic option at this time) please advise.
* I'm posting here (vs admin_menu) because I believe this is a general question regarding hook_menu; it's only incidentally related to admin_menu.
Comments
I'm thinking I should go to
I'm thinking I should go to the views module resources to find how to callback a view, but would still really like insight into what function to callback to in order to display a node.
Thanks!
>but would still really like
>but would still really like insight into what function to callback to in order to display a node.
Thanks mattyoung ...
Thanks mattyoung ... node_page_view() is just the thing!
At first I didn't see the benefit in wrapping the call to node_page_view() in a module function, preferring to 'keep it simple' with, eg.,
But I'm thinking the point is to avoid hard coding the nid in the routing table. Although here it's hardcoded in the module, at least one doesn't have to rebuild the routing table to make a change. And ideally, one would add logic to determine the correct nid programmatically, perhaps from a config setting or some other source. You are truly committed to all things good and pure, I see!
This doesn't work: 'page
This doesn't work:
'page arguments' => array (node_load(123))The menu system can only store literal string values or path positional index as arguments. It cannot store node object. For this, you need to use the %node wildcard. Here is how you can do this:
Somehow, it is working! I
Somehow, it is working! I tested it before my post. Maybe it's saving the serialized result of the function call? (Or, more likely, I'm missing something). Interesting, though...
Yes, it's saving a
Yes, it's saving a serialized instance of {node}, so it looks like it works... until you edit the underlying node. Thanks for saving me from potential heartache!
Thank you!!
Thank you!!
_
this is a very old post-- there's an admin_menu api that can add and alter the menu items now.