Given the URL mysite.com/foo/bar/term-name I was attempting to create a block view that displayed some related content based on the term name.

I set the contextual filter to:

Content: Has taxonomy term ID.

I set the WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED to:

specify validation criteria: Validator -> taxonomy term and restricted it to the appropriate category, with Filter value type set to "Term name converted to Term ID" and "Transform dashed in URL to spaces in term name filter values."

This works splendid when I enter in the term name into the "preview with contextual filters".

In order to get the Term passed to the block, I set the WHEN THE FILTER VALUE IS NOT AVAILABLE to "Provide default value", and selected Raw value from URL, and selected 3 for the path component. (again, so it would work on foo/bar/TERM-NAME or foo/bar/TERM-NAME/baz etc..)

The issue is in views_plugin_argument_default_raw.inc :

<?php
if ($arg = arg($this->options['index'])) {
      return
$arg;
    }
?>

Drupal's arg function is going to give the *internal path* arguments, so in my case foo/bar/TERM-NAME got unaliased back to node/9999 and TERM-NAME was not being passed to my block.

Either views_plugin_argument_default_raw.inc needs to be adjusted to go back to the original $_SERVER['REQUEST_URI'], or it should be renamed to Raw value from internal drupal path after aliasing. Because how it works now is *not* actually from the URL.

Comments

I just ran into this problem. Is there a way to work around it? I need it to work from the URL alias, not the internal Drupal path.

sub

I had the same problem. I switched the Provide default value to PHP and used the drupal_get_path_alias() function to retrieve the url and then ran it through a preg_replace before returning. Sounds like a lot but it was quick and simple and worked fine.

Status:Active» Fixed

Well there is an option "Use path alias" at least on the current dev version which does exactly what you all wanted.

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Active

Hi,

I always get the same issue even though my views version is at 7.x-3.x-dev (2012-Sep-27)... or did I missed something?

Thanks

Sorry... I really missed something, ... I don't know if this is yet related to this issue, but my purpose is not really the same :

In my case the view block is shown on a node page with an automatic alias : "content/title-of-the-node" (pathauto)... When I add a contextual filter to the block view like specified in this current issue, I attended somthing like "content/title-of-the-node/term-name" to work... (but 404 Error). Though "node/%nid/term-name" works correctly.

Can someone help?

Thanks in advance.

... Or could someone tell if this won't be possible? thanks

Status:Active» Closed (fixed)

jramby - it seems your problem isn't with views but with aliases. You don't have an alias for content/title/term-name pointing to /node/nid/term-name.

#3 and #4
just to confirm, with older version of views I had to use code like:

<?php
$pathOrig
= isset($_GET['q']) ? $_GET['q'] : '';
$pathOrig = drupal_get_path_alias($pathOrig);
$path = explode('/', $pathOrig);
$thetype=$path[0];
return
$thetype;
?>

but in the latest views version there is a select box option:

Use path alias instead of internal path

which does this for you.

In other words, if there is an alias for node/345 you'll be dealing with the alias.

I'm having trouble with a multilanguage site and Views contextual filters. The non-default language versions of the site get their own path components, which seems to interfere with retrieving content ID from URL.
The default language of the site is missing the extra path component, making the path too inconsistent for the "Raw value from URL" option (however, when I just use "Content ID from URL", the filter works on the default language version atleast).

Is there some magic PHP code I could use with "Provide default value [as] PHP Code" instead, or is this perhaps a bug which can be fixed?

My view is a block, and the field I'm running the context filter on is a Entity Reference field.

I confirm that Issue still exist!
Views 7.x-3.7
Pathauto 7.x-1.2
May anyone confirm that it was fixed in dev versions?

I try to filter block with integer field, using pathauto for node urls, so when I test in Views Preview url like: site.com/type/cat/1 it shows filtered results, when 3-d argument is aliased with pathauto it shows nothing! And Of course I set Use path alias! I tried to use Integer field value in path Pattern but still see no option how to do this. May anyone help with detailed Example of PHP code Argument variant of solution untill this will be fixed?

I tried to use this code to provide Default Argument:

$node = node_load(arg(1));
return $node->field_integer_field[0]['value'];

Maybe I miss something?

Status:Closed (fixed)» Postponed (maintainer needs more info)

Could you provide precise guidelines to reproduce the problem?

Hi Rune!
I try to make views similar content views block, and I have integer select field in content type that I want to use as argument in views block.
I generate pathauto url for node like this: site.com/type/section/title So in the path I get section as integer field, and label of field is aliased with pathauto.

I create block views and add integer field as argument (contextual filter) and try to set default value as Raw value from node url. Argument number 2 and I set option to use pathauto, as I suppose it should take aliased field label and use it as argumnet, and option to use pathauto makes the magic -> gives value from aliased label.

You may say tha I could use Field value token in path but there is some problem with it https://drupal.org/node/2010424
Field tokens Issue https://drupal.org/node/691078

So as a solution I would like not to use Raw value from path and provide default argument from $node load variable or something...
I tried to use this code but it doesn't work for me.

$node = node_load(arg(1));
return $node->field_integer_field[0]['value'];

Token 7.x-1.5
Views 7.x-3.7
Pathauto 7.x-1.2

I made a test: I manually changed url path from site.com/type/section/title to site.com/type/2/title
And Raw value from Url № 2 + set Use path alias filters the view!!! So somehow integer field value will work in path, and integer field label will not!

Thanks for your interest Rune!

Version:7.x-3.3» 7.x-3.7

@ RunePhilosof

Yes, this is still an issue

I set up a small example on a test site of mine. Here is the layout, it is very simplistic.

So I have Jobs that are posted on the site (content type: Job Posting) ex. example.com/content/manager-job (path auto)
I have applications (content type: Job Application)
I have a few views setup with relationships so that the site administrators can see who applied to what jobs

But take for instance that my site STAFF (role) that would be reviewing the jobs that were applied for, needed a TAB on the actual job post so they could see who applied for it, just by clicking the tab.

Here is where the view issue happens.

I create a view (related jobs) with the fields I need and a contextual filter so that I can see just the applications that were for that job.
Page settings: Path: /content/%/applicants (path to the job post, plus the applicants part which will be the tab
menu: Tab: applicants

Contextual filter: Content:Job (which is a field from the application content type)
when filter value is not in URL: provide default value: RAW value from URL => path component: 2 and Use path alias is checked
(I do this because the job posting that I want the tab to be on is here: ex. example.com/content/manager-job (path auto) >>> manager-job should be what the filter uses to know the applications for that job.

I saved the filter. and no queries are being made to the database. If I use the node/45 in the preview area it works, but not if I type content/manager-job

It does not seem to use the manager-job as the component it looks for.

Help would be appreciated.

Title:Views Contextual Filter "Provide Default Value: Raw value from URL" Does not use the URL, it uses internal Drupal Path."Use path alias" setting of "Content: NID" contextual filter does not work
Version:7.x-3.7» 7.x-3.x-dev
Component:Miscellaneous» exposed filters
Category:feature» bug
Status:Postponed (maintainer needs more info)» Active

Here's an export based on the latest dev version of Views. It displays a node based on the URL /exampleview/% using the "Content: NID" contextual filter.

The problem is that "Use path alias" setting in the Content: NID contextual filter doesn't work.

Expected behavior:

For a node with nid 34 and path alias mypagealias: Visiting /exampleview/mypagealias should display the node.

Actual Behavior:

Visiting /exampleview/mypagealias does not display the node but /exampleview/34 works, the opposite of what is expected based on the "Use path alias" setting being checked.

<?php
$view
= new view();
$view->name = 'exampleview';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'exampleview';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'exampleview';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['nid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['nid']['default_argument_options']['use_alias'] = TRUE;
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'exampleview/%';
?>

Expected behavior:

For a node with nid 34 and path alias mypagealias: Visiting /exampleview/mypagealias should display the node.

Thats not the expected behavior actually. What you are doing is telling views to filter based on the NID, So it expects a numeric NID. If there isn't a NID in the URL for some reason, then you can set how it should behave. In the case of exampleview/mypathalias since mypathalias isnt a nid, you are saying "get the argument from the path, and use the path alias of the current page which in this case is simply 'exampleview/%'. The 'get raw value from the url' does just that - gets exactly what is in the URL. If you happen to be on a node page or taxonomy page, the 'URL' could be either what the user sees in their browser window, or what is stored behind the scenes. But there isnt any function to turn 'mypathalias' back into a NID. In order to do that you'd have to 'specifiy validation criteria', select PHP code, and turn mypathalias back into a NID with some code. (i.e $handler->argument = drupal_get_normal_path($argument) etc. (I havent tested that, but thats the idea.

It might be more clear if these were two options -

  1. Get the raw value from the url (which *only* uses the path alias (i.e. the URL that the user can see.)
  2. Get the raw value from the internal path (ie. the unaliased path like node/34 or exampleview/%)

In any case what you are trying to do isn't built into views out of the box, because on *your* site 'mypathalias' happens to be an alias for a node, and it doesnt have any other parts, but many, many sites have much longer aliases for nodes, like /content/mypathalias or /articles/category/mypathalias - so views cant assume that a single url part is actually a whole alias.

I can't get a simple block to use the url to display content that has the term... uggg....

$view = new view();
$view->name = 'product_page_headers';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Product Page Headers';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Product Page Headers';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['default_field_elements'] = FALSE;
/* Field: Content: Product Page Header */
$handler->display->display_options['fields']['field_product_page_header']['id'] = 'field_product_page_header';
$handler->display->display_options['fields']['field_product_page_header']['table'] = 'field_data_field_product_page_header';
$handler->display->display_options['fields']['field_product_page_header']['field'] = 'field_product_page_header';
$handler->display->display_options['fields']['field_product_page_header']['label'] = '';
$handler->display->display_options['fields']['field_product_page_header']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_product_page_header']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['field_product_page_header']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_product_page_header']['settings'] = array(
  'image_style' => '',
  'image_link' => '',
);
/* Contextual filter: Content: Catalog (taxonomy_catalog) */
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['id'] = 'taxonomy_catalog_tid';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['table'] = 'field_data_taxonomy_catalog';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['field'] = 'taxonomy_catalog_tid';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['default_action'] = 'default';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['default_argument_options']['use_alias'] = TRUE;
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['validate_options']['vocabularies'] = array(
  'shop' => 'shop',
);
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['validate_options']['type'] = 'name';
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['validate_options']['transform'] = TRUE;
$handler->display->display_options['arguments']['taxonomy_catalog_tid']['validate']['fail'] = 'empty';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'product_page_header' => 'product_page_header',
);
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['title'] = FALSE;

Issue summary:View changes

typo fix