I've enabled the "Transform Spaces for Dashes" option for the taxonomy-name argument.
However, URL's with dashes don't get recognized by views as valid term names.
After a few minutes of looking around, the problem seems to be in the
File: modules/taxonomy.views.inc,
Class: views_plugin_argument_validate_taxonomy_term,
Function: validate_argument
It seems that the validate_argument function never transforms dashes to spaces, and thus fails to recognize the transformed URL's as containing valid term names.
Ideally, it would somehow read the views_handler_argument_string option['transform_dash'] and run a quick strtr($argument, '-', ' ');, as we see in includes/argument.handlers.inc:860
Comments
Comment #1
merlinofchaos commentedThis is an unfortunate limitation of the validators (They don't communicate with the arguments to be able to cope with transformations) and something I've chosen to put off addressing for 2.1.
Comment #2
dergachev commented@merlinofchaos, I see what you mean.
By the way, it was extremely confusing to me about what role validators play in configuring an argument.
In my case, selecting the validator "Taxonomy Term" for the argument of type "Taxonomy ID" displayed a field letting me select which vocabulary.
At the time, it seemed necessary that I should have a chance to select which vocabulary my terms are being matched against. (In fact, for the argument type "Taxonomy Name", it very well might be). Only after reflection did I realize that tid is sufficient, and that this validation is entirely optional.
It might help if the fields associated with a particular validator are wrapped in a fieldset clearly labeling that.
Comment #3
merlinofchaos commentedThey're in a fieldset in rc1 already.
Comment #4
merlinofchaos commentedComment #5
hankpalan.com commentedSo I have Terms "Romans, Holy Spirit"
I set up a feed for those terms including the Transform spaces to dashes in URL in the argument.
When I go to path/romans/feed it works perfectly.
When I go to path/holy-spirit/feed it doesn't work.
If I take out the Transform spaces to dashes in URL option and go to path/holy spirit/feed it works perfectly.
So based on this issue and thread your telling me that I have to wait until Views 2.1 comes out to fix this problem?
Comment #6
lavignej commentedWas this fixed in version 2.1? I seem to be having this same issue, and I'm using Views 2.1.
Comment #7
iLLin commentedYea I tracked this all morning... Well what I ended up doing was modifying the $_GET['q'] variable in a hook_init in one of my custom modules. I have my alias's setup as so:
/games
/games/taxonomy-term
So it was easy for me to go in and explode the 'q' var by the / and then do a str_replace on the array[1] to remove the dashes and put in spaces. That way I fix the q var before views sees it.
Obviously this is a work around.
Another solution is to add a path alias through the admin.
System path /games/taxonomy term
Alias path /games/taxonomy-term
But thats retarded to add EVERY single taxonomy term like that.
Anyway this works for me until this is solid in views. As long as you have unique and controlled paths, you shouldn't have a problem doing something like what I did.
Comment #8
klavs commentedThis issue still exists in views-2.8 :(
I have taxonomy terms with spaces in them (like "flying cows") - and use the taxonomy term as the title of the view shown (so having it be "flying-cows" isn't good :)
When I enable the option for arguments: taxonomy term called "Transform spaces to dashes in URL" it works in the live preview section - it shows my "flying cows" - when I enter "flying-cows".
Yet - when I do it on the site - there's no results for "flying-cows" - but results for "flying%20cows" :(
is the "transform spaces to dashes in URL" (which actually seems to do the opposite - ie. convert dashes in URL to spaces in term name) not being applied when the views is actually used - and only in the live preview pane?
Comment #9
klavs commentedIt's actually a bug (unless I've misunderstood something and just hi-jacked an unrelated issue (hope not :)
Comment #10
klavs commentedI found that if I uncomment the check in handlers/views_handler_argument_string.inc line 148 (and the belonging } ) - it does as expected on site.
It seems the problem is that: $this->options['transform_dash'] - is unset/empty in "function query" - which it shouldn't be.
Since it's a class - and I'm using php-5.2.0 (Debian 4.0 - aka. etch) - I'm guessing it may be a php issue.
perhaps someone can confirm if this works on newer php versions?
Comment #11
merlinofchaos commented"Transform spaces to dashes" would take a space and turn it into a dash.
You want to take a dash and turn it into a space.
That would be "Transform dashes to spaces". The option you're looking for is in the taxonomy argument validator.
Comment #12
klavs commentedNever the less - when I disable the option for arguments: taxonomy term called "Transform spaces to dashes in URL" - it no longer converts dashes in url's to spaces before doing taxonomy search.
It seems it's not suppose to have that effect on Live Preview ? I'll go look in the code for the "reverse" option.
Comment #13
merlinofchaos commentedIn an argument, the setting "Transform spaces to dashes in URL" is for use on summary views. It does not transform the input, it transforms the output.
Comment #15
glass.dimly commentedAlright, so this issue is still active.
That is, when a taxonomy term is handed to views as an argument, it usually has dashes in it. Views doesn't think it's a taxonomy term because it doesn't recognize the dashes.
This would be an easy patch to write.
Comment #16
iLLin commentedEasy eh? So how would you handle these two taxonomy terms?
Gun Show
Scooby-doo
-Please let us know.
I think taxonomy needs a "url-safe" / "unique" name. Then we wouldn't have to worry about this.
Comment #17
klavs commentedor modules linking to taxonomy names should not replace spaces with - and use %20 instead - it works (although it may not be so seo friendly)
or perhaps sent a double-dash when a dash is really meant (like escaping it) - and then otherwise replace a dash with a space.
Comment #18
jbrauer commentedWhat about changing this to replace spaces with - to replace spaces with + which is properly interpreted by the argument handler?
Comment #19
xjmSee also: #368414: Views 2 Transform spaces to dashes in URL option. That issue is about the same end result, but has mixed posts about the validator issue (as in this issue) and term names containing hyphens.
Here is a simple view to demonstrate this issue. Note: I am using MySQL so case can be ignored.
Working version
First, a view with a term argument that uses the spaces-to-dashes option, without any validator set. This version of the view works.
Here is the query this view runs (from the views preview) when I specify the argument
eau-claire. (The actual term name is Eau Claire.)Non-working version
Now, here is a second version of the same view. The only change made is that I added a Taxonomy Term validator, checked the name of the vocabulary that contains the term "Eau Claire," and set this validator to Term name or synonym.
With this view, the argument
eau-clairefails validation, so no query is run. If I instead useEau Claire, the query is:So, a potential solution would, if possible, be to allow the validator to use the same term-rewriting options that the argument handler itself uses. The hyphen seems like the best character to me, but it could even be provided as a user-configurable option, since (hopefully) the user knows what sorts of arguments are expected.
Comment #20
mrfelton commentedsubs
Comment #21
hanoiisubscribing, and also I wonder, if this option is to change the output, what's the use for this if that output cannot then work as a link? Is this supposedly to be used only for pathauto aliases?
I have a term "Term One", if I transform it, the URL displays as "Term-One" but the views does not recognize it as a valid term, is this the same issue all are describing, isn't it?
EDIT: I am not using validators.
Comment #22
jalneal commentedSubscribing
Comment #23
PixelClever commentedThere is a fairly simple workaround for this issue. I posted a short tutorial on how to get this done on my website at : http://pixelclever.com/how-remove-spaces-when-using-term-names-or-node-t...
Comment #24
iamjon commentedMarking as closed from lack of activity.
Comment #25
pieterdcAfter 10 years, this is still a valuable hint (for the Drupal 7 version of Views, at least):