Include Sample PHP Code for Usage of $r for Template Usage
stefanpro - September 25, 2007 - 04:15
| Project: | Site User List |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | pukku |
| Status: | active |
Jump to:
Description
I can do some PHP hacking, but did not study the higher sciences of Drupal yet. I didn't get the $r in the "use eval for this template" working, as much as I tried. I guess that I am not the only one having troubles with this feature.
Would be nice, if the accompanying text would provide a short sample code.
Thanks for a great module!
Stefan

#1
Hi! If you can tell me what you were trying, and show me your sample code, I should be able to help you. Mostly,
$ris just an array of all the visible values being shown. There are two extra values added to the array (@_baseand@_dest) which can also be used.Ricky
#2
I tried: expression, return expression, return (expression). I tried $r[fieldName] and $r['fieldName']. Nothing worked.
The issue is, that the Profile module doesn't handle the fields of type "URL" correctly, i.e. it handles only http://, https://, ftp://, but not mailto: So, I did some hack in other modules to get a mailto: URL clickable. Right now the fields hold the whole string: mailto:user@domain. I wanted in the Site user list appear it as a clickable link.
In mySQL, table profile_fields the corresponding record says fid=14, name=profile_pub_eMail.
In table profile_values there would be then a record fid=14, value=mailto:user@domain.
So, the expression to create the link would be something like (depending how the query was):
"<a href=\"" . $result['value'] . "\">" . substr($result['value'],7) . "</a>"Hope this is understandable.
Right now I gave it up and hard coded the link creation into the module, but I would prefer to get it done the proper way, also because otherwise I have to code again with every new release of the module.
And, I assume that I am not the only dumb one out there who has troubles... so an example in the description and/or a link to a page with more examples would surely be good.
Thanks a lot!
Stefan
#3
Hi! So, assuming that you have enabled the 'profile_pub_eMail' field for display, the correct template would probably be something like:
return "<a href=\"" . $r['@profile_pub_eMail'] . "\">" . substr($r['@profile_pub_eMail'], 7) . "</a>";All column names should be prefixed with an '@' sign — this is to follow the conventions of Drupal's
t()function. Otherwise, you mostly had it...Let me know if this doesn't work...
Ricky
#4
Thank you for quick help, but unfortunately, it doesn't work.
I checked that the field name is correct (it is the profile_fields.name, not .title, right?).
Then copied and pasted your code into the form entry box.
This is what the HTML source shows:
<a href=""></a>Means: the $r does not get expanded at all.
I did last time already a print_r ($r) and I know that $r is really set, but somehow the eval doesn't work.
Thanks,
Stefan
#5
What did you get as the result of the print_r($r)?
Ricky
#6
Array
(
[@uid] => 5
[@profile_pub_eMail] => mailto:user@domain.com
[@profile_BirthDate] => a:3:{s:3:"day";s:2:"19";s:5:"month";s:1:"7";s:4:"year";s:4:"1984";}
[@_base] => /
[@_dest] => destination=site_user_list
)
I deleted some fileds (therefore the empty lines).
I can use $r hard coded in site_user_list.module like this though:
if ((substr($r['@profile_pub_eMail'],0,7) == "mailto:") AND $f == "@profile_pub_eMail"){$myTemplate = ... (the formatted HTML line, using $r['@profile_pub_eMail'])
}
$row[] = drupal_eval('<?php ' . $fields[$f]['template'] . '?>') . $myTemplate;
// the $myTemplate is the "hard coded" string,
//I keep the Template field in the configuration form empty.
Thanks,
Stefan
#7
See this node for the reason $r is not available to be eval'd.