I have been toying around with using [termpath] and [termpath-raw] tokens in the uploadpath and filefield_paths module and it gives unexpected results. It appears to be applying pathauto's cleaning functions right in the hook_token_values() implementation thus leaving unexpected results outside the pathauto module itself.

If you look at the code in pathauto.module... the function pathauto_cleanstring() should not appear in the pathauto_token_values() function. pathauto should only apply it's cleaning methods outside the hook_token_values() implementation.

CommentFileSizeAuthor
#9 pathauto-422798-10.patch1.03 KBsp3boy

Comments

greggles’s picture

I believe this is necessary because of the way that the terms are used.

If you need similar tokens suitable for a filesystem path, I suggest you copy the function and alter it slightly to provide the exact tokens you need.

If you have suggestions on how the function can be modified to suit your needs and still work for pathauto, please leave a patch.

greggles’s picture

Status: Active » Closed (works as designed)
chey’s picture

Here is my concern. When a module makes a token available for use it cannot assume that it will only be used as it pertains to the module that made it available. In this case the pathauto module shouldn't assume it is the only module using that token.

Outside of pathauto's functionality some users may want the [termpath*] tokens left alone rather than having various strings removed as it is in my case. But where the tokens do apply to the pathauto module I like to have them go through pathauto's string replacements.

Maybe this is more of a feature request?? Not sure. But def not good token design in my opinion.

greggles’s picture

Well, I'm certainly open to patches that make this work for pathauto and other modules, but it is so easy to create tokens (especially now that #437842: create a token starterkit module and documentation so people know how to use it is in) that I'm not motivated to work on this.

chey’s picture

Understandable. Thanks for the info! If I get the time I'll re-open and submit a patch.

sp3boy’s picture

Status: Closed (works as designed) » Active

I am also scratching my head with this now, in relation to using termpath-raw in Filefield_paths and Image modules.

Before I start proposing code changes, can I just confirm that I understand the situation correctly?

In pathauto_token_values(), the taxonomy parent terms are run through pathauto_cleanstring() before being concatenated to the front of $catpath and $catpath_raw.

However when the child term is added to these variables from $category->name it is not run through pathauto_cleanstring().

What this means for me in practice is that if I have an Image Gallery hierarchy like:
Parent: Master gallery
Child: General gallery

the value returned by the pathauto_token_values() for [termpath-raw] is "Master-gallery/General gallery"

...note the space replaced by hyphen in the parent, not the child.

If I use the token for creating URL aliases, the second space character is also replaced by a hyphen, due I suspect to the URL going through pathauto_clean_token_values().

I guess I'm advocating two things here:

1. Treating all levels of a taxonomy hierarchy the same.
2. Treating the parent components of the catpath_raw like the child, so I would not get hyphens in parent term text.

The first of those seems straightforward, the second may have more ramifications than I can immediately see.

Feedback please?

greggles’s picture

1. Treating all levels of a taxonomy hierarchy the same.

Yes.

2. Treating the parent components of the catpath_raw like the child, so I would not get hyphens in parent term text.

No :(

For pathauto's purposes we need to use pathauto_cleanstring on these.

sp3boy’s picture

For pathauto's purposes we need to use pathauto_cleanstring on these.

Even though the URLs are later processed by pathauto_clean_token_values() which applies pathauto_cleanstring() to everything?

Leaving it to pathauto_clean_token_values() seems to work OK for the "child" portion of the taxonomy hierarchy, why not the parent portion?

sp3boy’s picture

Status: Active » Needs review
StatusFileSize
new1.03 KB

Further to my point about pathauto_clean_token_values() above, here is a patch for the one-line change that I'm proposing.

If someone can give me a test scenario in which my change would impair the existing creation of URLs by Pathauto, I will happily have a re-think.

I have tested this patch on a site that uses [termpath-raw] in both Pathauto Node path settings for Image URLs (e.g. "image/[termpath-raw]/[title-raw]") and Filefield_paths Image filepath (e.g. "images/[termpath-raw]"). With the patch, the URLs still get hypens in place of spaces, the file paths get hyphens in place of spaces (and other clean-up changes) if the Filefield_paths "Cleanup using Pathauto" option is enabled.

dave reid’s picture

Status: Needs review » Closed (won't fix)

At this point I don't think we should change everyone's expectations of how this token should work. If you need a customized termpath token, you can always create a custom module that provides its own tokens. As such, I'm marking this as won't fix.