I would like an alter hook so that I can limit the scope of the behavior of path_alias_xt in another module. For example, to run additional regular expression validation on the urls. The reason this is helpful is that the default behavior of the path_alias_xt allows any additional url arguments on any url. It would be good to be able to limit the scope of this with custom code.
I propose to add one line to the module:
diff --git a/modules/path_alias_xt/path_alias_xt.module b/modules/path_alias_xt/path_alias_xt.module
index d2aee66..6b58b98 100755
--- a/modules/path_alias_xt/path_alias_xt.module
+++ b/modules/path_alias_xt/path_alias_xt.module
@@ -106,6 +106,7 @@ function path_alias_xt_url_inbound_alter(&$path, $original_path, $path_language)
$src .= '/' . $user->uid;
}
$path = $src . drupal_substr($original_path, $pos);
+ drupal_alter('path_alias_xt_url_inbound_path', $path, $original_path, $path_language);
return;
}
}
Then I can add additional validation, for example, limiting the scope of the path_alias_xt to certain url patterns with regular expressions.
Comments
Comment #1
oknateComment #2
oknateHere's a use case for this patch. I want to limit the path_alias_xt from working on all other paths, except if they have "slide/1" on the end, for example. That way, if I have a valid url such as "videos", an extended alias that I don't want, such as "videos/my-random-string" will 404, as it should. Right now, out of the box, path_alias_xt doesn't have a way to limit this. This is why I'm proposing an alter hook.
This is how I'm planning to use it, in another module called path_alias_xt_limiter:
Comment #3
rdeboerHi oknate,
Thank you for your suggestion.
But you can already do this by implementing the same function that
path_alias_xt_url_inbound_alter(&$path, $original_path, $path_language)implements, namelyhook_url_inbound_alter().All you have to do is to make sure that your hook is called after path_alias_xt's hook.
You do this by making sure the module weight of your module is higher than the weight of path_alias_xt, which it will be by default as the weight of path_alias_xt is -1 and the default weight for modules is zero.
Or am I missing something?
Rik
Comment #4
oknateRik,
Yes, you're right. As long as the module weight is lower. So if path_alias_xt is -1, my module that makes changes needs a lower weight to fire after it, say -2. In this case, the patch isn't needed. It needs to be lower because drupal_get_normal_path runs the modules in reverse order.
from drupal_get_normal_path:
I had the purl module enabled which was changing the $original_path variable, so I thought I couldn't do it with a simple hook_url_inbound_alter, but I think that's just an issue with the purl module, that was causing the $original_path variable to change before getting to my custom module.
Comment #5
rdeboerHi oknate,
Thank your for your response. In that case I'm closing this issue.
Rik