Please document that you can use $tid and $tname in your PHP expression.

I finally saw them mentioned on the project's home page, but they are not mentioned on the README.txt or in the "Enter path" field description (and that's probably the best place to mention them).

CommentFileSizeAuthor
#7 tax_redirect_php_filter.patch493 bytesfriolator
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Agileware’s picture

Status: Active » Fixed

I have added it to the enter path description and the readme. I also made a couple of other updates to the readme as it was a little out of date.

These changes should be in the dev version sometime today and in the next release.

Status: Fixed » Closed (fixed)

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

doublejosh’s picture

Version: 5.x-1.3 » 6.x-1.3

$tid seems to have no value for me?!

friolator’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Component: Documentation » Code
Category: feature » bug

I'm using the latest dev release, and $tid is coming up blank every time.

friolator’s picture

Status: Closed (fixed) » Active
friolator’s picture

Just to clarify what I'm seeing:

We're using taxonomy redirect to change a path from taxonomy/term/[TID] via a custom module of our own that handles some rewriting of URLs and paths. I've ruled out our module, which works correctly if I hardwire a tid in the php editor in the taxonomy redirect admin page. That is, if I pass our function a valid tid such as "497" it works perfectly. If I pass it the variable $tid, it comes up blank. So in tracing this back, I located what I think is the code in the module, at line 506:

<?php
    $text .= '$tid = ' . $term->tid . '; ';
?>

I changed that to:

<?php
    $text .= '$tid = 497; ';
?>

...and it had no effect. The value of $term->tid is not empty, though. sending that out to watchdog from within taxonomy_redirect.module shows that line 506 has the correct value for $term->tid, it's just not getting picked up by the $tid in our PHP.

In the PHP evaluation textarea, here's our code:

<?php 
watchdog("TID", $tid);
$stuff = array('what' => 'resort', 'type' => 'term', 'id' => $tid, 'path' => TRUE);
return cd_misc_generate_link( $stuff );
?>

cd_misc_generate_link() is a function that creates a link or a path. the watchdog call returns nothing. Again, this works perfectly if we hardwire a $stuff[id] value, but not if we use $tid, so the problem is somewhere in the taxonomy redirect module. I've tried following the code, but i'm not familiar enough with the PHP filter to know exactly what's going on.

friolator’s picture

Status: Active » Needs review
FileSize
493 bytes

Ok, figured this out. The problem seems to be that at line 515, the wrong string is being passed to check_markup():

<?php
  $path = trim(_taxonomy_redirect_exec_filter($redirect->path, $redirect->filter));
?>

should be:

<?php
  $path = trim(_taxonomy_redirect_exec_filter($text, $redirect->filter));
?>

Patch attached, rolled against the latest dev build.

--- taxonomy_redirect.module	Wed Sep 16 17:50:19 2009
+++ taxonomy_redirect2.module	Wed Sep 16 17:55:24 2009
@@ -512,7 +512,7 @@ function taxonomy_redirect_term_path($te
     $text = $redirect->path;
   }
 
-  $path = trim(_taxonomy_redirect_exec_filter($redirect->path, $redirect->filter));
+  $path = trim(_taxonomy_redirect_exec_filter($text, $redirect->filter));
   $separator = $redirect->separator_replace;
   $remove_text = $redirect->remove_text;
   $path_case = $redirect->path_case;
Agileware’s picture

Title: document $tid and $tname » $tid and $tname PHP variables don't work

Marked #606864: give the PHP code variables as a duplicate of this issue

Agileware’s picture

Status: Needs review » Fixed

Committed fix in #7.

Thanks for the patch friolator.

friolator’s picture

cool!

Status: Fixed » Closed (fixed)

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

alanom’s picture

Any chance of resolved, tested bug fixes like this being migrated into the stable/recommended release? A year on and this is still broken in the (2008) 6.1.3 stable release.