Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've written a patch to allow replacement patterns in PHP code fields. This patch is based on discussions/code snippets from an identical issue relating to markup fields: http://drupal.org/node/810190. Credit to bartclarkson for his original post: http://drupal.org/node/810190#comment-3109330.
Example usage:
if ($data->node_data_field_homepage_media_type_field_homepage_media_type_value == "0") {
print '[field_video_fid]';
} else {
print '[field_image_fid]';
}
Comment | File | Size | Author |
---|---|---|---|
#5 | viewCustomFieldWithPatch.zip | 17.97 KB | HAbbas |
views_customfield_handler_field_phpcode-replacement_patterns.patch | 2.69 KB | matt.elkins |
Comments
Comment #1
BWPanda CreditAttribution: BWPanda commentedI needed this functionality and was going to try this patch, but then found this: http://drupal.org/node/467190#comment-3081790
For example, you can use something like this out-of-the-box:
Does this help? If so, this patch might not be needed...
Comment #2
Rj-dupe-1 CreditAttribution: Rj-dupe-1 commentedPatch looks good, much less invasive than the one over in http://drupal.org/node/810190#comment-3446480 and works well for me. Drupal 6.18, patched custom field 6.x-1.x-dev.
Comment #3
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #4
deggertsen CreditAttribution: deggertsen commentedsubscribing
Comment #5
HAbbas CreditAttribution: HAbbas commentedIncluded the above mentioned patch to the latestly available module "Views Custom Field" and has made the whole module availble for others to use. You could directly use this module instead of adding patch separately since the same patch has been updated with this attached module. Thanks for the provided patch. It helped me to resolve an issue since iam novice in drupal.
Comment #6
demonrage CreditAttribution: demonrage commentedhello, the patch worked like a charm, but i have a strange problem.
i have a view that grab latest articles, in every article it have a title, thumbnail and a button to like on facebook or twitter, here is the original code:
and here is my code
if i use [path] replacement pattern in the code, it doesn't display the Facebook button completely, and display the tweet link without any graphic or (like counter), but it provide the link path in a correct way.
what i have been missing, i really tried hard to figure it out with no result
Comment #7
demonrage CreditAttribution: demonrage commentedactually this patch can't work with custom markup either
Comment #8
lunk rat CreditAttribution: lunk rat commentedWorks great for me, thanks for this! Patched against 6.x-1.x-dev and I am using all sorts of replacement patterns within my custom field PHP and they work flawlessly. This should be committed as it is very nice to be able to leverage the formatters and other standard views features within your custom field logic.
Comment #9
Anthony Pero CreditAttribution: Anthony Pero commentedThis worked for me, I was able to find the correct field name to use in the $data object by looking at the view code on the bottom of the Display.
Comment #10
Bartezz CreditAttribution: Bartezz commented@BWPanda: I've worked with $data->field_image_fid; before and it works for some fields, but I needed the term IDs returned by a Taxnomy: All terms field. A result like this isn't a simple db field return and therefor isn't available in $data object. Through the patch in #1 it becomes available via [tid]...
Works like a charm!! Please commit, it's been half a year...
EDIT: But still not useful in my case :( problem is that the tokens are rendered after the PHP is rendered, so the value of the tokens can't be used in PHP equations...
Cheers