创建链接到其父级的菜单项

发布于 2024-10-19 13:22:35 字数 114 浏览 2 评论 0原文

我一直在寻找低点和高点来做到这一点。我想以编程方式创建一个链接到其父级的普通菜单项。类似于默认菜单任务的概念,但只是一个普通的菜单项。有人这样做过吗?

我想要一些可以用 drupal 钩子做的事情。

I've been searching low an high to do this. I want to create a normal menu item programatically that links to its parent. Similar to the concept of default menu task, but just a normal menu item. Has anyone ever done this?

I want something that I can do with one of the drupal hooks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尝蛊 2024-10-26 13:22:35
$items['parent'] = array(
    'title' => 'I am parent',
    'page callback' => 'drupal_get_form',
    'page arguments' => 'get_parent',
    'access arguments' => array('access parent'),
    'type'      => MENU_NORMAL_ITEM,
);

$items['parent/child'] = array(
    'title' => 'I am child link of parent',
    'page callback' => 'drupal_get_form',
    'page arguments' => 'get_children_for_thisparent',
    'access arguments' => array('access children of parent'),
    'type'      => MENU_NORMAL_ITEM,
);

这应该可以解决问题:)

$items['parent'] = array(
    'title' => 'I am parent',
    'page callback' => 'drupal_get_form',
    'page arguments' => 'get_parent',
    'access arguments' => array('access parent'),
    'type'      => MENU_NORMAL_ITEM,
);

$items['parent/child'] = array(
    'title' => 'I am child link of parent',
    'page callback' => 'drupal_get_form',
    'page arguments' => 'get_children_for_thisparent',
    'access arguments' => array('access children of parent'),
    'type'      => MENU_NORMAL_ITEM,
);

This should do the trick :)

倾城花音 2024-10-26 13:22:35

假设您想将其放在主菜单下,

    $item['form_example'] = array(
        'title' => 'Example menu',
        'description' => 'This is an example menu item',
        'type' => MENU_NORMAL_ITEM,
        'page callback' => 'custom_function',
        'menu_name' => 'main-menu',
    );

    return $item;

您将在主菜单下获得菜单项(清除缓存)。诀窍是添加一个键“menu_name”。

要获取menu_name,请打开菜单管理页面,然后单击任意根菜单上的“编辑菜单”。 URL 将类似于“SITE_URL/admin/struct/menu/manage/main-menu/edit”。查看最后一个(这里是主菜单)之前的 url 段。

对于第二种情况,您可能希望将其放置在主菜单的“Home”下。代码是。

$item['form_example'] = array(
    'title' => 'Example menu',
    'description' => 'This is an example menu item',
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'custom_function',
    'menu_name' => 'main-menu',
    'plid' => 218,
);

return $item;

在这里,我向关联数组添加了一个键 pld,它是菜单项(此处为“Home”)的 mlid,它将成为该菜单项的子项。对于这种情况,它将是主菜单的子菜单。

要获取 mlid,您必须执行与上述相同的操作,转到菜单管理页面并单击列表链接,然后单击菜单项上的编辑,例如 SITE_URL/admin/struct/menu/item/218/edit,这样您就可以获得mlid 就这样完成了。

笔记。如果您从后端更改此菜单层次结构或其他设置,您将始终有重置选项来重置它,并且重置后它将像代码中描述的那样运行。

Suppose you want to place it under Main menu,

    $item['form_example'] = array(
        'title' => 'Example menu',
        'description' => 'This is an example menu item',
        'type' => MENU_NORMAL_ITEM,
        'page callback' => 'custom_function',
        'menu_name' => 'main-menu',
    );

    return $item;

You will then get the menu item under Main menu (clearing cache). The trick is adding a key 'menu_name'.

To get the menu_name please open the menu administration page, and click on 'edit menu' on any root menu. URL will be like 'SITE_URL/admin/structure/menu/manage/main-menu/edit'. Look at the url segment just before the last(here main-menu).

For the second case you might want to place it under Home of main menu. The code is.

$item['form_example'] = array(
    'title' => 'Example menu',
    'description' => 'This is an example menu item',
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'custom_function',
    'menu_name' => 'main-menu',
    'plid' => 218,
);

return $item;

Here, I have added a key plid to associative array, it is the mlid of the menu item('Home' here) for which it will be a child. For this case it will be child of Home menu.

To get the mlid you have to do the same as described above, goto menu administration page and click list links and then click edit on the menu item, e.g. SITE_URL/admin/structure/menu/item/218/edit, thus you can get the mlid and thus its done.

Note. If you change this menu hierarchy or other settings from back-end, you will always have reset option to reset it, and after resetting it will behave like described in the code.

黯淡〆 2024-10-26 13:22:35

您只需要创建一个新的菜单项,与其父项具有相同的路径

You just need to create a new menu-item, that has the same path as its parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文