$tid and $tname PHP variables don't work

mariuss - March 14, 2009 - 09:01
Project:Taxonomy Redirect
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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

#1

Justin W Freeman - March 15, 2009 - 22:49
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.

#2

System Message - March 29, 2009 - 22:50
Status:fixed» closed

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

#3

doublejosh - April 22, 2009 - 23:57
Version:5.x-1.3» 6.x-1.3

$tid seems to have no value for me?!

#4

friolator - September 16, 2009 - 20:33
Version:6.x-1.3» 6.x-1.x-dev
Component:Documentation» Code
Category:feature request» bug report

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

#5

friolator - September 16, 2009 - 20:35
Status:closed» active

#6

friolator - September 16, 2009 - 21:18

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.

#7

friolator - September 16, 2009 - 22:02
Status:active» needs review

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;

AttachmentSize
tax_redirect_php_filter.patch 493 bytes

#8

Justin W Freeman - November 14, 2009 - 04:20
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

#9

Justin W Freeman - November 14, 2009 - 04:28
Status:needs review» fixed

Committed fix in #7.

Thanks for the patch friolator.

#10

friolator - November 14, 2009 - 17:19

cool!

#11

System Message - November 28, 2009 - 17:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.