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

merlinofchaos’s picture

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

dergachev’s picture

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

merlinofchaos’s picture

They're in a fieldset in rc1 already.

merlinofchaos’s picture

Category: bug » feature
hankpalan.com’s picture

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

lavignej’s picture

Version: 6.x-2.0-beta4 » 6.x-2.1

Was this fixed in version 2.1? I seem to be having this same issue, and I'm using Views 2.1.

iLLin’s picture

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

klavs’s picture

Version: 6.x-2.1 » 6.x-2.8

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

klavs’s picture

Category: feature » bug

It's actually a bug (unless I've misunderstood something and just hi-jacked an unrelated issue (hope not :)

klavs’s picture

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

merlinofchaos’s picture

Status: Active » Fixed

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

klavs’s picture

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

merlinofchaos’s picture

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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

glass.dimly’s picture

Status: Closed (fixed) » Active

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

iLLin’s picture

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

klavs’s picture

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

jbrauer’s picture

Category: bug » feature

What about changing this to replace spaces with - to replace spaces with + which is properly interpreted by the argument handler?

xjm’s picture

Title: Taxonomy Argument Ignore "Transform Spaces for Dashes" » Taxonomy Argument Ignores "Transform Spaces for Dashes" when a validator is used
Version: 6.x-2.8 » 6.x-2.11

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

$view = new view;
$view->name = 'hyphen_test';
$view->description = '';
$view->tag = 'test';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'nid' => array(
    'label' => 'Nid',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'name' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'glossary' => 0,
    'limit' => '0',
    'case' => 'ucwords',
    'path_case' => 'lower',
    'transform_dash' => 1,
    'add_table' => 0,
    'require_value' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '26' => 0,
      '5' => 0,
      '4' => 0,
      '6' => 0,
      '7' => 0,
      '16' => 0,
      '13' => 0,
      '14' => 0,
      '19' => 0,
      '8' => 0,
      '9' => 0,
      '21' => 0,
      '10' => 0,
      '15' => 0,
      '22' => 0,
      '11' => 0,
      '12' => 0,
      '18' => 0,
      '17' => 0,
      '25' => 0,
      '20' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_cck' => 'content_taxonomy',
    'default_argument_cck-content_taxonomy' => 'field_type',
    'default_argument_cck-nodereference' => 'field_parent_issue',
    'content_taxonomy_format' => 'tid',
    'argument_default_cck_nodereference_format' => 'nid',
    'argument_default_cck_nodereference_delta' => '0',
    'param_name' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'forum' => 0,
      'announcement' => 0,
      'dfm_site_page' => 0,
      'document' => 0,
      'external_news' => 0,
      'graduate' => 0,
      'hr_profile' => 0,
      'newsletter_article' => 0,
      'newsletter_issue' => 0,
      'person' => 0,
      'press_release' => 0,
      'short_bio' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '22' => 0,
      '6' => 0,
      '11' => 0,
      '8' => 0,
      '9' => 0,
      '7' => 0,
      '13' => 0,
      '21' => 0,
      '1' => 0,
      '2' => 0,
      '17' => 0,
      '12' => 0,
      '20' => 0,
      '15' => 0,
      '19' => 0,
      '16' => 0,
      '14' => 0,
      '10' => 0,
      '18' => 0,
      '3' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'short_bio' => 'short_bio',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));

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

SELECT node.nid AS nid
 FROM node node 
 LEFT JOIN term_node term_node ON node.vid = term_node.vid
 INNER JOIN term_data term_data ON term_node.tid = term_data.tid
 WHERE (node.type in ('short_bio')) AND (term_data.name = '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.


$view = new view;
$view->name = 'hyphen_test';
$view->description = '';
$view->tag = 'test';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'nid' => array(
    'label' => 'Nid',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'name' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'not found',
    'glossary' => 0,
    'limit' => '0',
    'case' => 'ucwords',
    'path_case' => 'lower',
    'transform_dash' => 1,
    'add_table' => 0,
    'require_value' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '26' => 0,
      '5' => 0,
      '4' => 0,
      '6' => 0,
      '7' => 0,
      '16' => 0,
      '13' => 0,
      '14' => 0,
      '19' => 0,
      '8' => 0,
      '9' => 0,
      '21' => 0,
      '10' => 0,
      '15' => 0,
      '22' => 0,
      '11' => 0,
      '12' => 0,
      '18' => 0,
      '17' => 0,
      '25' => 0,
      '20' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_cck' => 'content_taxonomy',
    'default_argument_cck-content_taxonomy' => 'field_type',
    'default_argument_cck-nodereference' => 'field_parent_issue',
    'content_taxonomy_format' => 'tid',
    'argument_default_cck_nodereference_format' => 'nid',
    'argument_default_cck_nodereference_delta' => '0',
    'param_name' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'forum' => 0,
      'announcement' => 0,
      'dfm_site_page' => 0,
      'document' => 0,
      'external_news' => 0,
      'graduate' => 0,
      'hr_profile' => 0,
      'newsletter_article' => 0,
      'newsletter_issue' => 0,
      'person' => 0,
      'press_release' => 0,
      'short_bio' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '10' => 10,
      '22' => 0,
      '6' => 0,
      '11' => 0,
      '8' => 0,
      '9' => 0,
      '7' => 0,
      '13' => 0,
      '21' => 0,
      '1' => 0,
      '2' => 0,
      '17' => 0,
      '12' => 0,
      '20' => 0,
      '15' => 0,
      '19' => 0,
      '16' => 0,
      '14' => 0,
      '18' => 0,
      '3' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'name',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'short_bio' => 'short_bio',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));

With this view, the argument eau-claire fails validation, so no query is run. If I instead use Eau Claire, the query is:

Query	

SELECT node.nid AS nid
 FROM node node 
 LEFT JOIN term_node term_node ON node.vid = term_node.vid
 INNER JOIN term_data term_data ON term_node.tid = term_data.tid
 WHERE (node.type in ('short_bio')) AND (term_data.name = 'Eau Claire')
 

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.

mrfelton’s picture

subs

hanoii’s picture

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

jalneal’s picture

Subscribing

PixelClever’s picture

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

iamjon’s picture

Status: Active » Closed (works as designed)

Marking as closed from lack of activity.

pieterdc’s picture

Issue summary: View changes

After 10 years, this is still a valuable hint (for the Drupal 7 version of Views, at least):

If I take out the Transform spaces to dashes in URL option and go to path/holy spirit/feed it works perfectly