So I have tried my head at this thing for the longest time. I got my code working by using the UI of the module but I now want to use it in my own module. I just can't make it work and the documentation is really bad for this thing if there is someone who comes and doesn't understand hook_boot() and what to do inside it. This is the code I have so far.

/**
 * Implementation of hook_boot()
 */
function pathargs_boot() {
  // implemented?
}

/**
 * Implementation of hook_url_inbound_alter()
 */
function pathargs_url_inbound_alter(&$result, $path, $path_language) {
  watchdog("Path Arguments", "Result: {$result} Path:{$path}");
  if($result == 'chn') {
    $path = 'node/1222/chn/profile/3';
  }
}

Comments

Dave Reid’s picture

Status: Active » Fixed

You just leave hook_boot() empty. And make sure to submit the form at admin/build/modules so that the change can be picked up by the Drupal bootstrap system. The parameters make it quite clear you should be altering $result, and not $path as well.

wmasterj’s picture

Status: Fixed » Active

Thank you for your help. I don't mean to sounds harsh concerning the documentation but it can be hard to anticipate how much help someone else needs. And more detailed documentation might gain more implementations of your module.

Just to be sure: I create a module. Install it, and then after it is installed I go to the module list page again and just click submit? This enables the bootstrap system to pick up the change? Because hook_boot() has been empty from the start and now I don't know why it's not working.

And the documentation is not clear on $path VS $result. Because for $result it only says: "The Drupal path based on the database. If there is no match in the database it will be the same as $path."

But for $path it says "The path to be rewritten", im confused I guess since also your examples change $path and not $result. If it says "to be rewritten" then I think, OK, that it the paramater I want to rewrite, on the other hand $result is passed by reference and I don't see any instructions to return $path.

I tried changing $result instead of $path but that didn't work. It doesn't run the function at all since I don't get any log messages or anything that I have inside that function, is my signature wrong? Using URL Alter's UI works so I know that is installed fined.

wmasterj’s picture

Still cracking my head against this thing and it isn't working. Help would really be appreciated. Clearing caches and resubmitting the module list seems not to work. Current code in my *.module:

/**
 * Implementation of hook_boot()
 */
function pathargs_boot() {
  // remain empty, only needed to let Drupal bootstrap system know to load this module earlier.
}

if (!function_exists('custom_url_rewrite_inbound')) {
  function custom_url_rewrite_inbound(&$result, $path, $path_language) {
    return pathargs_url_inbound_alter($result, $path, $path_language);
  }
}

/**
 * Implementation of hook_url_inbound_alter()
 */
function pathargs_url_inbound_alter(&$result, $path, $path_language) {
  watchdog('Path Arguments', "$result + $path");
  if($result == 'chn') {
    $result = 'node/1222/chn/profile/3';
  }
}

Not even the watchdog call is running. I realized that watchdog() might not be defined but echo() doesn't run either.
hook_boot() runs, but I never get anything from hook_url_inbound_alter(...), it never seems to run.

Also started a thread on Stackoverflow:
http://stackoverflow.com/questions/4587660/using-module-url-alter-and-it...

arcane’s picture

I was able to get this to work with the following code in my own custom module called site_support.

function site_support_url_inbound_alter(&$result, $path, $path_language) {
  if ($result == "node/1") $result = "node/2";
}

function site_support_boot() {
  $c = "value";
}

Also, I re-saved the module when adding the hook_boot function. In addition, I double checked that bootstrap = 1 in the system table record for my module.