url 中的区域设置模块和语言前缀

发布于 2024-09-13 20:29:30 字数 811 浏览 0 评论 0原文

我一直在研究模块,并且很清楚 hook_menu 用于传递 url 参数进行回调。例如:

$items['webtv/block/%/playlist/edit/%'] = array(
    ...
    'page callback' => 'drupal_get_form',
    'page arguments' => array('webtv_playlist_form', 5, 2),
    ...
);

和回调 as

function webtv_playlist_form($form_state, $fifth_arg, $second_arg){
...
}

除了 arg() 函数之外,还有另一个实用程序可以通过位置获取 url 参数。

$second_arg = arg(2);
$fifth_arg = arg(5);

当我启用区域设置模块以使 Web 成为多语言时,URL 会使用前缀作为语言符号进行分类。示例:

en/webtv/block/%/playlist/edit/%

OR

nl/webtv/block/%/playlist/edit/%

这个东西将参数的逻辑位置移至右侧,现在参数的正确位置(根据示例)是:

$second_arg = arg(3);
$fifth_arg = arg(6);

如何设置独立于此类参数位置问题的模块?

I had been working on module and well aware of hook_menu for passing url arguments to call back. For instance:

$items['webtv/block/%/playlist/edit/%'] = array(
    ...
    'page callback' => 'drupal_get_form',
    'page arguments' => array('webtv_playlist_form', 5, 2),
    ...
);

and callback as

function webtv_playlist_form($form_state, $fifth_arg, $second_arg){
...
}

Beside that arg() function is another utility to get url arguments by their positions.

$second_arg = arg(2);
$fifth_arg = arg(5);

When I enable locale module to make web as multilingual, URLs are classified with prefix as language symbol. Example:

en/webtv/block/%/playlist/edit/%

OR

nl/webtv/block/%/playlist/edit/%

This thing displaces the logical placement of arguments to right, now the correct placement of arguments (according to example) is:

$second_arg = arg(3);
$fifth_arg = arg(6);

How to set-up module independent of such argument placement issues?

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

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

发布评论

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

评论(1

落日海湾 2024-09-20 20:29:30

查看 Drupal 核心代码(例如 node_menu()< /a>),当 locale.module 启用时,使用菜单占位符的菜单回调不会调整为工作,local.module 也不会更改从其他模块定义的菜单。
事实上,
language_initialize(),调用Drupal bootstrap 包含以下代码:

case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
case LANGUAGE_NEGOTIATION_PATH:
  // $_GET['q'] might not be available at this time, because
  // path initialization runs after the language bootstrap phase.
  $args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();
  $prefix = array_shift($args);
  // Search prefix within enabled languages.
  foreach ($languages as $language) {
    if (!empty($language->prefix) && $language->prefix == $prefix) {
      // Rebuild $GET['q'] with the language removed.
      $_GET['q'] = implode('/', $args);
      return $language;
    }
  }

该代码正在删除 URL 中传递的语言 ID。
如果 locale.module 设置正确,则在启用模块时不应更改菜单回调定义。

Looking at Drupal core code (in example, node_menu()), menu callback using menu placeholders are not adjusted to work when locale.module is enabled, nor local.module alters the menus defined from other modules.
In fact, language_initialize(), called on Drupal bootstrap contains the following code:

case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
case LANGUAGE_NEGOTIATION_PATH:
  // $_GET['q'] might not be available at this time, because
  // path initialization runs after the language bootstrap phase.
  $args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();
  $prefix = array_shift($args);
  // Search prefix within enabled languages.
  foreach ($languages as $language) {
    if (!empty($language->prefix) && $language->prefix == $prefix) {
      // Rebuild $GET['q'] with the language removed.
      $_GET['q'] = implode('/', $args);
      return $language;
    }
  }

The code is removing the language ID passed in the URL.
If locale.module is correctly set, the menu callback definitions should not be changed when the module is enabled.

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