views:

32

answers:

1

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?

+1  A: 

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.

kiamlaluno

related questions