I´m using the following code to retrieve the taxonomy id from the URL and use it as a contextual filter.
When I use it on a computed field as it is shown below it works OK.

$nid = arg(1);
$path_alias = drupal_get_path_alias('node/' . $nid);
$partes = explode("/", $path_alias);
$dato = $partes[2];
$entity_field[0]['value'] = $dato;

When I use the same code on a views contextual filter it doesn´t work:

$nid = arg(1);
$path_alias = drupal_get_path_alias('node/' . $nid);
$partes = explode("/", $path_alias);
$dato = $partes[2];
return $dato;

If I replace line 4 to force a value into $dato it works OK too, of course for only one taxonomy term.

$nid = arg(1);
$path_alias = drupal_get_path_alias('node/' . $nid);
$partes = explode("/", $path_alias);
$dato = 43;
return $dato;

I would like to receive any help on what I need to correct on the second example to make it work as a contextual filter.
Thanks!

Comments

glanster created an issue. See original summary.

Subhransu.addweb’s picture

Can you please give URL from which you get tid. From your code it seems that you are getting nid from URL.

Thanks!

glanster’s picture

Hi!

The URL can be something like the following:

http://localhost/GLSIMBDES/?q=content/72067/45

I´m quite sure that the code returns the tid because when I use it on a computed field as in the first example it works OK and it displays the tid. I´m using 2 as index for the "exploded" variable.
The problem is that the same code does not work on a contextual filter. It does if I force the value as in the third example.

glanster’s picture

Issue summary: View changes
glanster’s picture

After some new tests I found that the problem is related with Entity References View Widget so I´m transferring the support request to that module issue´s page.

https://www.drupal.org/node/2629966

mustanggb’s picture

Priority: Major » Normal
Issue tags: -PHP, -contextual, -filter, -taxonomy, -id
renatog’s picture

Perfect @glanster.

Let's follow the issue on Issue Queue of Entity Reference View Widget

Thank you very much.

Regards

renatog’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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