以编程方式添加菜单项/链接到Drupal菜单? [英] Programmatically add menu item/link to Drupal menu?
问题描述
的条目 John Doe
其中John Doe是指向用户个人资料页面的链接。我想以编程方式执行,或者如果可以通过界面完成,那将是很好的。
你不能添加菜单中的HTML-ified项目。菜单项总是包装在锚标签中,并且将过滤出HTML。改变这种行为在技术上是可能的,但会引起许多未知的副作用。
你想要的是一个简单的主题覆盖 ,或自定义块(可能没有标题和一些其他项目符号)。
您可以使用 hook_block 。这最后一个选项是快速的,但是很多人为表演和良好做法的原因不鼓励:您不应该将PHP存储在您的数据库中。
编辑:评论后只是名字:
要插入只是名称,您只需要使用hook_menu创建模块。
global $ user;
$ items ['path /%uid'] = array(
'title'=> $ user-> name,
'description'=>'description',
'page callback'=>'drupal_get_form',//在此处填写回调:表示页面内容的函数
'页面参数'=>数组(''),
'访问回调'=>'',
'访问参数'=>数组(''),
'weight'=> 0,
'menu_name'=& ',
'type'=> MENU_NORMAL_ITEM,
);
是关于你想要的。
I have a Drupal Menu which I created through the interface. I wish to add an entry which says
Hi, John Doe
Where "John Doe" is a link to the User's profile page. I would like to do this programmatically or if it can be done through the interface then that would be great.
You cannot add HTML-ified items to the menu. Menu-items are always wrapped in an anchor tag and will filter out HTML. Changing this behaviour is technically possible, but will cause a lot of unknown side-effects.
What you want, is either a simple theme override, or a custom block (potentially without a title and with some other bullets).
You can create a block with hook_block or by simply typing the HTML, with some PHP into a new block, using the PHP-input filter. This last option is quick, but is discouraged by many people for performance and "good practices" reasons: you should not store php in your database.
EDIT: After comment about "just the name":
To insert "just the name" you simply need to create module with a hook_menu.
global $user;
$items['path/%uid'] = array(
'title' => $user->name,
'description' => 'description',
'page callback' => 'drupal_get_form', //Fill in the callback here: function that renders the page content.
'page arguments' => array(''),
'access callback' => '',
'access arguments' => array(''),
'weight' => 0,
'menu_name' => 'Navigation',
'type' => MENU_NORMAL_ITEM,
);
Is about what you want.
这篇关于以编程方式添加菜单项/链接到Drupal菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!