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

CommentFileSizeAuthor
#17 328064-17.patch3.4 KBGeorg
#9 328064-9.patch3.83 KBGeorg

Comments

Julien PHAM’s picture

btw 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.

nicholas.alipaz’s picture

Title: Better alias generation required » Cut off Alias at Specified Length and Add an Extension

I 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

greggles’s picture

Just 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.

nicholas.alipaz’s picture

I 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?

Georg’s picture

Title: Option to add a suffix to aliases » Cut off Alias at Specified Length and Add an Extension

Hi,
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)

nicholas.alipaz’s picture

Title: Cut off Alias at Specified Length and Add an Extension » Option to add a suffix to aliases

Now 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?

Georg’s picture

I'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.

nicholas.alipaz’s picture

XOR: http://drupal.org/patch/create

Hopefully that might get you started.

Georg’s picture

StatusFileSize
new3.83 KB

Thank you for the hint, nicholas.alipaz.

The patch I created is attached.

comments:

  • in the API.txt I added the extra parameter. Unfortunately the $language parameter wasn't in there before so I did not write a description on that.

    Please read through the description in the API.txt on the $suffix parameter, whether it is clear on what it does or not.
  • The changes in the pathauto.inc are anly adding the $suffix parameter/variable to pathauto_create_alias().
  • This whole thing now needs to be implemented and made availible in the admin area.

Georg (was: XOR)

nicholas.alipaz’s picture

Thanks 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.

greggles’s picture

This whole thing now needs to be implemented and made availible in the admin area.

It 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.

Georg’s picture

It 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.

I 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?

nicholas.alipaz’s picture

XOR, 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:

/**
 * Implementation of hook_token_list().
 */
function tokennodetitle_token_list($type = 'all') {
  if ($type == 'global' || $type == 'all') {
  }
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['title-raw-short']  = t("The raw title shortened to 60 characters.");
  }

  return $tokens;
}

/**
 * Implementation of hook_token_values().
 */
function tokennodetitle_token_values($type, $object = NULL) {
  $values = array();
  switch ($type) {
    case 'global':
      break;
    case 'node':
      $node = $object;
      $values['title-raw-short']        = substr($node->title, 0, 60);
      break;
  }
  return $values;
}

And in my corresponding .info:

name = Token Node Title
description = A token for the title of a node that is shortened to 60 characters
dependencies[] = token
core = 6.x

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.

Georg’s picture

nicholas.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...

nicholas.alipaz’s picture

well, 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.

Georg’s picture

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.

In 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:

Tokens are small bits of text that can be placed into larger documents via simple placeholders, like %site-name or [user].

Meaning: it simply replaces these placeholders.

[title-short-raw][dup-token].html

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.

Georg’s picture

Title: Cut off Alias at Specified Length and Add an Extension » Option to add a suffix/extension to aliases, by setting a place for the numbering
StatusFileSize
new3.4 KB

Here 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?

bartezz’s picture

Interesting, subscribing... was looking for such functionality in D6

dave reid’s picture

Status: Active » Closed (duplicate)