Hi,
I have noticed some strange behaviours in pathauto.
1/ If we would like to append ".html" in a path and the path is already too long, then pathauto does not append the ".html". Instead it cuts the path, and remove the end, even the ".html". Perhaps there should be an option for an extension to paths, extensions that will never be removed. Pathauto should instead cut more the title instead of removing the extension.
2/ Sometimes a path will end with the separator, which is not very pretty, I think in those cases pathauto should remove the separator as well. (and with my firs point above, remove the separator before putting the .html extension)
3/ There should be a way to remove words by node type, or even by pathauto parts. For instance, if the link for a node is : taxonomy term/node title, I would like to be able to remove some words in the node title but not in the taxonomy term.
4/ There should be a way to "update" aliases in bulk mode, so if we use path redirect with pathauto, then we ask for a bulk update, aliases should be updates and the path redirect table as well.
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 328064-17.patch | 3.4 KB | Georg |
| #9 | 328064-9.patch | 3.83 KB | Georg |
Comments
Comment #1
Julien PHAM commentedbtw I think a useful feature would be the possibility to cut down the alias at a given character, for example I would like to cut down the alias after a coma. Then if pathauto sees a coma, it will stop the alias generation, and remove the coma.
This will allow shorter aliases for long titles.
And a possibility as well to allow a path redirect integration even if we uncheck pathauto for a node to put our own title, so pathauto will put info into path redirect tables to do the good redirection.
Comment #2
nicholas.alipaz commentedI too am looking for this feature.
Really long URL's get clipped instead of adding ".html" to the end of the path. It would be preferable that one could specify that a url get clipped at a specified length and then have an extension tacked on such as ".htm", ".html" or etc.
Assuming that some url's may already exist when creating a page, then additional support for adding the number before the .html would be needed as well.
/my-cool-page-0.html
Comment #3
gregglesJust for the record, I'm opposed to the idea. The UI for it would be paintful.
I suggest you investigate the #437842: create a token starterkit module and documentation so people know how to use it tokenSTARTERKIT so you can create your own tokens that will do things like limit themself to a certain length so that they are sure to fit.
Comment #4
nicholas.alipaz commentedI just tried the idea out on a new site. I have it doing substr($node->title, 0, 60) for the token. That works fine, but I can't think of any way to move the number inside of the .html when the path is a duplicate.
my token is [title-raw-short]
my nodes are: [title-raw-short].html
How would I tell it to add the extra -x before .html?
Comment #5
Georg commentedHi,
I changed the pathauto.inc to add ".html" to the end of every alias:
Row 301: $maxlength = min(variable_get('pathauto_max_length', 100), 128)-5;
Subtracting 5 characters from the maxlength for the ".html" suffix.
Row 306: if (_pathauto_alias_exists($alias.'.html', $src, $language)) {
Adding the suffix ".html" to the alias.
Row 308: for ($i = 0; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - strlen($i)) . $separator . $i . '.html', $src, $language); $i++) {
Adding the suffix ".html" to the alias.
Row 322: _pathauto_set_alias($src, $alias.'.html', $module, $entity_id, $pid, $verbose, $old_alias, $language);
Adding the suffix ".html" to the alias.
.
It would be better to do that with a variable. Easiest to implement it in the function as a parameter. Something like this:
Row 239: function pathauto_create_alias($module, $op, $placeholders, $src, $entity_id, $type = NULL, $language = '', $suffix='') {
Row 301: $maxlength = min(variable_get('pathauto_max_length', 100), 128)-strlen($suffix);
Subtracting the length of the suffix from the maxlength to get room for the suffix.
Row 306: if (_pathauto_alias_exists($alias.$suffix, $src, $language)) {
Adding the suffix to the alias.
Row 308: for ($i = 0; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - strlen($i)) . $separator . $i . $suffix, $src, $language); $i++) {
Adding the suffix to the alias.
Row 322: _pathauto_set_alias($src, $alias.$suffix, $module, $entity_id, $pid, $verbose, $old_alias, $language);
Adding the suffix to the alias.
Now We just need someone to implement the option to set the suffix in the admin area.
Yours,
Georg (was: XOR)
Comment #6
nicholas.alipaz commentedNow that we figured out a solution for cutting the alias off at a certain point. i will retitle this to only add the suffix.
Thanks for the ideas XOR. Did you or can you write a patch for the changes you are mentioning?
Comment #7
Georg commentedI'm quite new to drupal as a whole, but I believe that I probably could write a patch. Right now though I don't know how to proceed. I'll look for documentation and how-to's, maybe you can help me here.
Comment #8
nicholas.alipaz commentedXOR: http://drupal.org/patch/create
Hopefully that might get you started.
Comment #9
Georg commentedThank you for the hint, nicholas.alipaz.
The patch I created is attached.
comments:
Please read through the description in the API.txt on the $suffix parameter, whether it is clear on what it does or not.
Georg (was: XOR)
Comment #10
nicholas.alipaz commentedThanks for posting the patch. I will see if I can give it a try this week. Hopefully others can find some time to test as well.
Comment #11
gregglesIt is very unlikely that we will ever add new junk to the admin UI to handle this. It will require some creative new thinking on how the UI can be made simpler.
Comment #12
Georg commentedI thought of a way that the suffix could be included without adding anything new to the UI.
Instead of adding a new edit field somewhere, we use the path-pattern fields. By using the pattern fields it gives us the adventage of defining a suffix for each content type seperately, without adding so many extra edit fields.
For this to work we could add a character which specifies where the suffix begins. In other words we specify a place in the pattern, where a number is added if a path-alias is already in use. Since # is in URLs for anchers (thus I assume no one uses this in automated aliases) and usually symbolises numbers, I thought of using #.
e.g.: [title-raw]#.html
Any thoughts on this?
Comment #13
nicholas.alipaz commentedXOR, I really like your idea of essentially adding a token to place the numbering for existing aliases in a specified place. That being said, this is really an issue of customizing the placement of the number on duplicate aliases. And it is no longer an issue of placement of the .html from what I can tell.
Do you guys think this could be done with a custom token? I think that the custom token might be the way to do it if workable. I was able to create a token that cuts the node title down to 60 characters, if I could detect when a token is a duplicate and add the number to the end then I think that would solve it.
In my tokennodetitle.module I have:
And in my corresponding .info:
This works great to shorten it. Perhaps if there were a way to detect whether the alias were duplicate and add the number within this token then we could avoid any alterations to the pathauto module.
Comment #14
Georg commentednicholas.alipaz, I at first did not understand, how what you sugested would help with the suffix problem. And to be honest, I still don't know it.
But what you wrote in your comment makes sense.
Adding a seperate Token for the numbering is a good idea. I didn't think of it this way.
But I believe that it would not be a token that can be in the normal token module or be connected to it. The pathauto module is looking for the duplicats and adds the numbering. Thus it would be a pathauto specific (only) "token".
I'll think of this some more. The problem I see right now is, that we would have to explain this somewhere. Because it would be a pathauto specific "token". We would have to add a hint on the adminpanel, which will not help make it any leaner, or we have to add a description to the manuel...
Comment #15
nicholas.alipaz commentedwell, the tokenstarter module already allows you to add any description you like next to the token in the admin area. I think if the token set the path to have the -0 or whatever number, before pathauto actually gets a hold of it to determine whether the path is a duplicate already then pathauto would never need to create duplicates.
In other words... recreate/steal the function for creating the -0 on the path, and put it in a token so the token would essentially do -0.html if the path existed already.
[title-short-raw][dup-token].html
if the path didn't exist would result in:
my-alias.html
if the path exists already:
my-alias-0.html
I will try to research the function for creating the -0 etc, a bit this week if I have time.
Comment #16
Georg commentedIn addition to that it would have to cut down the length of the path to the maxpathlength. At the moment both, adding the -# and cutting it to the maxlength, are done in the function, that 328064-9.patch extends.
If I understand you correctly you are thinking on moving these two functions to a token. For what I understand tokens are not meant to do this. Please correct me if I'm wrong, but on the token project site it reads:
Meaning: it simply replaces these placeholders.
The [dup-token] here would not be simply a replacement, but rather would have to check the whole string if it were existend as a path and if it were adding a -# in the tokens place.
I therefore think we can create a [dup-token], but not as an extension to the token module but rather it being a "dummy token" for the function pathauto_create_alias() to know where to cut the alias and add the numbering.
I hope you see what I mean. But if my reasoning is wrong, please correct me. Otherwise I'll write a patch next time I'm at home to demonstrate how this solution I described above would look like.
Comment #17
Georg commentedHere is my solution.
Please test it. See what can be done better!
right now it will simply replace the first # in a pattern with the numbering, if there needs to be one. Otherwise it will behave like before.
I didn't choose a [token-like] syntax, because I get an errormessage, saying that this token is not availible.
The variable-names I use might have to be chosen more wisely.
In addition to this, it might be nice to be able to choose, where the sperator(s) is(/are) set around the number. At the moment there is only one seperator placed in front of the number. What do you think? Should we look into this?
Comment #18
bartezz commentedInteresting, subscribing... was looking for such functionality in D6
Comment #19
dave reidMerging this issue into #179298: Make the 'unique' alias suffixes configurable.