For example, with example.com/en/apple/12/article/11/23, in hook_init() arg(0) returns "apple," as I expect; in hook_boot() it returns en which is language prefix of English.


That is because hook_boot() is invoked too early in the bootstrap process, which means:

  1. Not all the modules are loaded, including the Locale module that is the one that alter the path, and the reason why arg(0) returns "apple" in your example, when called in hook_init().
  2. The language has not been set; it is initialized during the DRUPAL_BOOTSTRAP_LANGUAGE phase, while hook_boot() is invoked during the DRUPAL_BOOTSTRAP_PAGE_CACHE phase.
  3. The call to drupal_path_initialize(), which alters $_GET['q'] with $_GET['q'] = drupal_get_normal_path($_GET['q']); is done during the DRUPAL_BOOTSTRAP_FULL phase, which is the last bootstrap phase.

Differently, hook_init() is invoked as last step done in the DRUPAL_BOOTSTRAP_FULL phase, which means all modules are loaded, the language has been set, and drupal_path_initialize() has been already called.

As side note, hook_boot() has been removed from Drupal 8; if you are using it, you will need to change your code. Using hook_init() is a possible alternative, since it is still used in Drupal 8.

  • so I should call drupal_path_initialize() manually in hook_boot()? – Mohammad Ali Akbari Mar 6 '12 at 11:22
  • If you call drupal_path_initialize() in hook_boot() you would get an error about a not defined function; as per first point, it would not make sense doing it because the module that alters the result is still not loaded. – kiamlaluno Mar 6 '12 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.