Drupal:为视图创建菜单项
我正在创建一个小型预订系统。您可以创建可保留类型的节点,例如投影仪。 我有一个正常显示的日历视图。我为节点引用添加了一个参数,但在定义页面回调时遇到问题。 有人可以帮我吗?
现在我想为不同的节点创建菜单项
function your_module_menu() {
$nodeid //semantic, node is loaded right
$items['reservate/nodeid/$year-w$week'] = array( // semantic, url is built right
'title' => t('Your Module Name'),
'description' => t('Menu's description.'),
'page callback' => 'page_callback_funtion',
'page arguments' => array('page callback arguments'),
'access callback' => 'your_module_access', // the function that validates access based on the user's role(s).
'access arguments' => array(array(role1', 'role2')), // list of roles authorized - note nested array.
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
@edit
ok,也许我没有解释清楚:)。我有一个内容类型:单元,可以保留。对于我创建的每个单元,我想生成一个菜单项(我可以在节点保存或更新时重建菜单)。菜单应该链接到一个视图,并将节点 ID(单位)作为 url 中的参数。
I am creating a small reservation system. you can create nodes of a type that can be reservated, like a projector.
I have a calendar view with normal displays. I addes an argument for the node reference, but I have problems defining the page callback.
Can someone help me out?
Now I want to create menu items for the different nodes
function your_module_menu() {
$nodeid //semantic, node is loaded right
$items['reservate/nodeid/$year-w$week'] = array( // semantic, url is built right
'title' => t('Your Module Name'),
'description' => t('Menu's description.'),
'page callback' => 'page_callback_funtion',
'page arguments' => array('page callback arguments'),
'access callback' => 'your_module_access', // the function that validates access based on the user's role(s).
'access arguments' => array(array(role1', 'role2')), // list of roles authorized - note nested array.
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
@edit
ok, maybe I didn't explain well :). I have a content type: unit, which can be reserved. for each unit I create, I want to generate a menu item (I can do a menu rebuild on node save or update). the menu should be linked to a view, with the node id (unit) as an argument in the url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定您到底想做什么,但如果您的目标是创建一个菜单项,而不是在自定义模块中定义的新页面,那么您应该使用 Drupal 中的菜单系统。您可以创建指向您网站上存在的任何 URL 的菜单项。
对于节点来说,这尤其容易,因为您可以直接在节点编辑/创建表单中执行此操作。
Drupal 缓存菜单,因此您无法创建包含动态部分的菜单项,例如用户 ID 等。如果您想做类似的事情,您应该创建一个通用回调,将用户重定向到动态 url 或根据用户显示内容。
更新
您不必在每次创建或删除节点时都重新构建菜单系统(这样可扩展性不太好),您可以只创建新的菜单项,使用
hook_nodeapi
,删除的时候也删除。menu_link_save
menu_link_delete
I'm not sure what exactly you are trying to do, but if your goal is to create a menu item, and not a new page that you define in your custom module, you should use the menu system in Drupal. You can create menu items pointing to any url that exists on your site.
For nodes this is especially easy, since you can do this directly in the node edit/create form.
Drupal caches the menues, so you can't create menu items with dynamic parts in them, like the users id etc. If you want to do something like that, you should create a common callback that either redirects the user to the dynamic url or display content based on the user.
Update
Instead of having to rebuild the menu system each time a node is created or deleted, which won't be very scalable, you could instead just create the new menu item, with
hook_nodeapi
, and delete it when it's deleted.menu_link_save
menu_link_delete
如果我理解正确,您将尝试在每次添加“单元”类型的新内容节点时自动创建一个菜单项。如果这是正确的,我建议使用模块规则和一小段 PHP 来根据各种系统事件(例如内容创建)创建自定义菜单项。您可能会发现我写的有关此主题的教程很有用:
http://jan .tomka.name/blog/programmatically-creating-menu-items-drupal
这个想法很简单:在规则模块中设置一条规则,以便在节点创建或删除时触发操作,并使用 Drupal API googletorp 提到的调用来实际操作菜单项。
If I understand correctly, you're trying to automatically create a menu item each time a new content node of type "unit" is added. If that is correct, I'd suggest using module Rules and a tiny snippet of PHP to have a custom menu item created on various system events, such as content creation. You may find the tutorial I wrote about this topic useful:
http://jan.tomka.name/blog/programmatically-creating-menu-items-drupal
The idea is simple: set up a rule in the Rules module for an action to be fired at the node creation or deletion and use the Drupal API calls that googletorp has mentioned to actually manipulate the menu items.
我找到了一种非常简单的方法,我只是创建了一个视图块,它创建了带有一些过滤器的链接。
简单,正是我所需要的,似乎无法理解为什么我没有早点想到这一点
I found a very simple way to do it, I just created a view-block which creates the links with some filters.
simple and exactly what I needed, can't seem to understand why I didn't think of that sooner