Drupal 7:如何创建不出现在站点导航中的菜单/路由项

发布于 2024-10-19 20:08:35 字数 1029 浏览 4 评论 0原文

如何在 Drupal 中创建不会自动呈现导航链接的新路线/菜单?

我正在尝试在 Drupal 中创建一个简单的页面回调,该回调不会显示在导航菜单中。

我有一个名为 helloworld 的模块。

.module 文件包含以下内容

function _helloword_page_callback()
{
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
    for following conventions.');
}

function helloworld_menu()
{
    $items['helloworld'] = array(
      'title'               => 'Hello World',
      'page callback'       => '_helloword_page_callback',
      'access arguments'    => array('content'),
      'type'                => MENU_CALLBACK
    );
    return $items;
}

这成功地在网站上公开了 URL

http://example.drupal.com/helloworld

但是,尽管如此,我仍然在左侧 (Bartik) 导航菜单中收到一个链接那么

'type'              => MENU_CALLBACK

,为什么这不起作用呢?我是否正确配置了菜单项?一个更可能的问题:我如何误解菜单类型常量/系统的使用?是否有额外的缓存需要清除而

drush cc all

无法处理?我还可以采取哪些其他步骤来调试此问题?

How can I create a new route/menu in Drupal that doesn't automatically render a navigation link?

I'm trying to create a simple page callback in Drupal that doesn't show up in the Navigation menu.

I have a module named helloworld.

The .module file contains the following

function _helloword_page_callback()
{
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
    for following conventions.');
}

function helloworld_menu()
{
    $items['helloworld'] = array(
      'title'               => 'Hello World',
      'page callback'       => '_helloword_page_callback',
      'access arguments'    => array('content'),
      'type'                => MENU_CALLBACK
    );
    return $items;
}

This successfully exposes a URL on the site of

http://example.drupal.com/helloworld

However, I'm still getting a link in the left hand (Bartik) navigation menu, despite the use of

'type'              => MENU_CALLBACK

So, why isn't this working? Am I configuring the Menu item correctly? A more likely question: How am I misinterpreting the use of the menu type constants/system? Are there additional caches to clear that

drush cc all

wouldn't take care of? What other steps can I take to debug this?

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

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

发布评论

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

评论(2

暗恋未遂 2024-10-26 20:08:36

一定还有其他问题(也许您忘记清除缓存?),因为即使使用 Bartik,它也能按预期工作。在该示例中,导航中仅显示“Hello 2”:

function helloworld_menu(){
    return array(
        'hello1' => array(
            'title'               => 'Hello 1',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content'),
            'type'                => MENU_CALLBACK
        ),
        'hello2' => array(
            'title'               => 'Hello 2',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content')
        )
    );
}

function helloworld_page_callback(){
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you for following conventions.');
}

顺便说一句,您的代码片段中存在拼写错误(helloroute_menu 应命名为 helloworld_menu),但我假设这是由于在 StackOverflow 上发布之前进行了代码简化所致。

There must be something else wrong (perhaps you forgot to clear the caches ?) because even with Bartik, it works as expected. In that example, only "Hello 2" is shown in the navigation:

function helloworld_menu(){
    return array(
        'hello1' => array(
            'title'               => 'Hello 1',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content'),
            'type'                => MENU_CALLBACK
        ),
        'hello2' => array(
            'title'               => 'Hello 2',
            'page callback'       => 'helloworld_page_callback',
            'access arguments'    => array('content')
        )
    );
}

function helloworld_page_callback(){
    return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you for following conventions.');
}

By the way, there is a typo in your snipplet (helloroute_menu should be named helloworld_menu), but I assume this is due to code simplification before posting on StackOverflow.

青芜 2024-10-26 20:08:36

查看菜单管理中的菜单链接。如果您在那里对其进行了自定义(例如重量更改),则即使您设置为回调类型,它也可能仍然存在。

如果是这种情况,您可以删除那里。

Check out that menu link in the menu administration. If you customized it there (weight change for example), it's possible that it remains even though you set to type to callback.

If that's the case, you can just delete there.

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