Reviewed & tested by the community
Project:
Views Custom Field
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 May 2010 at 18:57 UTC
Updated:
24 Oct 2014 at 15:47 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
johnmullin2003 commentedI really hope that this feature will be embedded in the next module release!!!
it is so important!!
Comment #2
fabianx commented+1
works great for me.
Best Wishes,
Fabian (LionsAd)
Comment #3
mstiExcellent!
This worked for me too!
I hope that this feature will make it into the next release.
Comment #4
intyms commentedIt works for me too.
Comment #5
interestingaftermath commentedCan you please expand this to the PHP Customfields?? When I use the Markup field and change the input to PHP it prints the raw text if I choose to use replacement patterns.
Comment #6
derhasi commentedDo you mean the PHP Input filter or the module's PHP Custom Field?
In the module's custom field, you should be able to use variables for the other fields' values, so I think there is no need to implement the replacement patterns.
Comment #7
bartclarkson commentedI had need for phpcode to return a string that can itself include tokens of other fields defined previously in the view.
Putting logic into any .tpl.php file is outside the desired trend, and this should include view override files.
The weakness of the $data variable, of itself, is that it doesn't include the finalized style rendering of anything relating to an FID (various filefield-driven output).
The following revised function in views_customfield_handler_field_phpcode.inc of 6.x-1.0 met the stated need.
An example of one of my values for a Customfield: PHP code is the following:
Comment #8
derhasi commentedI'd suggest to open a new issue for the PHP Custom field, so the above patch in #0 could be commited independently.
@bartclarkson - maybe you could post a patch for the PHP Custom Field?
Comment #9
ekbiddle commentedA patch for the PHP custom field to do this would be amazing.
I'm actually running into something that would greatly benefit from it, using the 5 generated thumbnails in flash video to actually show up in a view, but it requires some php and the [fid] to work, at least as far as I can figure out how to do it...
Comment #10
binaryreleases commentedIf anyone can help me on this one it would be useful.
autoplay controls>
Your browser does not support the
audioelement.i'm trying to get HTML 5 audio to work (the code above) with filefield. I have a filefield field one space up from Views Custom field and have installed the patch. What seems to happen though is that some how something strips all of the HTML back to
Your browser does not support the
audioelement.When I put the example in from here (https://developer.mozilla.org/En/HTML/Element/Audio) with replacement patterns turned off I can get it to work fine with firefox and safari fails as is expected.
autoplay>
Your browser does not support the
audioelement.However if I replace the url with the replacement code both safari and firefox fail with the code some how being stripped back to Your Browser regardless of whether HTML is being filtered by input filters or not.
If anyone has an idea on how to fix this I would love to know what it is.
thanks
Comment #11
binaryreleases commentedIf anyone can help me on this one it would be useful.
element.
/audio>
i'm trying to get HTML 5 audio to work (the code above) with filefield. I have a filefield field one space up from Views Custom field and have installed the patch. What seems to happen though is that some how something strips all of the HTML back to
Your browser does not support the <code>audioelement.When I put the example in from here (https://developer.mozilla.org/En/HTML/Element/Audio) with replacement patterns turned off I can get it to work fine with firefox and safari fails as is expected.
element.
However if I replace the url with the replacement code both safari and firefox fail with the code some how being stripped back to Your Browser regardless of whether HTML is being filtered by input filters or not.
If anyone has an idea on how to fix this I would love to know what it is.
thanks
Comment #12
alanom commented---edit after trying out bartclarkson's code snippet
Brilliant! It just works: with this, replacement patterns can be used in PHP fields.
Regarding the importance of being able to do this - as well as what bartclarkson explained about supporting Filefield fields, there are also many Views-generated fields that simply don't show up in $data exports at all. For example, Global Custom Text and Lightbox triggers. Without replacement patterns, we have to re-invent these processes in hard-code PHP, and duplicate this code in every PHP where it's needed customfield.
More importantly, with replacement pattern support, every module that integrates with Views will work with PHP Customfields. Without it, we need to rely on every future module contributor to create appropriate $data variables.
Comment #13
Will White commentedThis patch is a bit more radical, but it simplifies the code significantly and fixes several bugs by extending the existing views
views_handler_field_customhandler.Comment #14
intyms commented@Will White
Thank you for patch !
I applied it to the dev version. I tried to find the "replacement patterns" but i didn't find them.
Let me know please, how can i help to test the patch from #13. What is the scope (purpose) of that patch.
Once again thanks a lot for your contribution to this module!
Comment #15
steveoliver commentedWhile I can include tokens in php code, I cannot transform them - they stay just as they are - regardless of strtolower(), etc. functions applied to them... Any ideas?
-Steve
Comment #16
inforeto commentedAs a workaround, can use pairs of markup fields as 'wrappers', exclude from display and use them as tokens.
Comment #17
HippoOnDiet commentedBART!!! http://drupal.org/node/810190#comment-3109330 Your code is working on my side :)
Thank you for your code I put it in and it just display the replacment pattern.
Thanks again.
What I did, I changed On line 132-134:
function render($values) {
return $values->{$this->field_alias};
}
To your code.
Thanks again!
Comment #18
gstout commented+1 this is invaluable.
Comment #19
joecanti commented+1 the patch in #13 works great, but for some reason the fields which have a relationship arent displayed and I get an error - would this be a patch related problem or a more general views customfield problem?
Thanks, Joe
Comment #20
interestingaftermath commentedsubscribe
Comment #21
charles.holtzkampf commentedWondered if someone could assist me, I have no PHP knowledge so im struggling a bit.
I have installed the - To Do List Module - http://drupal.org/project/to_do
I created a view with the following fields:
User: Uid (excluded from display)
Node: Title
To do list: Deadline
To do list: Priority
To do list: Start date
To do list: Status
To do assigned users: Assigned user ID (excluded from display)
To do list: Buttons (excluded from display)
Customfield: PHP code
The following Tokens/Replacement Patterns are available based on the above fields
* [uid] == User: Uid
* [title] == Node: Title
* [deadline] == To do list: Deadline
* [priority] == To do list: Priority
* [start_date] == To do list: Start date
* [item_status] == To do list: Status
* [uid_field] == To do assigned users: Assigned user ID
* [buttons] == To do list: Buttons
* [phpcode] == Customfield: PHP code
* [markup] == Customfield: Markup
What I would like to accomplish is:
As, the button field has been excluded, I am trying to use the Customfield, to display that button. But only display that button if the current user is the author of the To Do node.
What ive aded to Customfield PHP code
What's happening
Nothing displays using the above code.
I know the [buttons] token works because when I use the following code, it displays the button.
So I assume something needs to be added so that the system can decide whether the current logged in user is the author of the node. Both the [UID] & [UID_FIELD] always display the same value if I ouput it, so I thuogh that would work but it doesn't.
Any help would be very much appreciated.
Charles
Comment #22
charles.holtzkampf commentedWorked it out:
Comment #24
petarb commentedI am trying to output a Gmap using this revised module. So far it works as expected (great work!) however I have run into a snag...
Using the above field replacements I can render [latitude] & [longitude] as text within php. For example:
However, the following doesn't seem to be working:
A long thin map appears, whatever size I put in on the Gmap, and I cannot see a marker, nor is it centred properly.
I am not a coder, so any help is appreciated. Thanks.
Comment #25
petarb commentedI overcame my issue above by using Gmap Field, however, the issue above in itself remains unresolved.
Comment #26
Punk_UnDeaDin views_customfield_handler_field_markup.php
change
return check_markup($value, $this->options['format'], FALSE);return check_markup(html_entity_decode($value), $this->options['format'], FALSE);Comment #27
gstout commentedCould this patch be included in the main release?
Comment #28
iantresman commentedYes please! Using tokens in Markup and/or PHP code would be easier for us novices... as long as you can also provide a list of available tokens.
Comment #29
3dloco commented+1
Comment #30
JesseNahan commentedI love using Custom File and appreciate tremendously the module and all related contributions. Bart's patch in #7 is terrific and working well. Thanks for that!
However, I'm having the same issue as steveoliver in #15. I'd like to be able to assign a token to a variable then manipulate that variable or use it in an if statement. A simple example where I'm retrieving a user's role (token is [rid]) in a view:
$role = '[rid]';
print $role."
";
print substr($role,0,5);
The "print $role" results in printing the user's role(s) in the view. However, printing the substring results in "[rid]" being displayed. In this example, the actual value of $role remains "[rid]" no matter what I do to manipulate the variable.
Comment #31
dkingofpa commentedSub
Comment #32
fabianx commentedInteresting progress here.
Comment #33
joelstein commentedHere is a two line patch which adds support for both Markup and PHP code fields.
Comment #34
JesseNahan commentedThanks for the patch. Perhaps I am applying the patch incorrectly, but I am not seeing a difference when I try to load a token into a variable and manipulate it. (Please see my note #30 above.) Was that an issue you were trying to address?
I'm grateful for any contribution to this terrific module!
Comment #35
joelstein commentedJesseNahan: You're correct. I wasn't thinking about how to manipulate the tokens, but simply read them in. My patch adds the tokens in after the PHP is evaluated. That is because the PHP is evaluated before the rest of the individual fields are rendered, which means the token replacements will be empty. We can't really swap them out without rewriting the Views integration, and I don't understand enough about the module to try to tackle this. Sorry!
Comment #36
YK85 commentedsubscribing
Comment #37
moheshmohan commentedhi everyone
i am new to drupal and this is my first post in drupal.org so plz forgive me if this is stupid
i really appreciate the custom field module and its awesome...
i have used the patch #7 Posted by bartclarkson and its working fine.
like jesse in #30 i too wanted the token to be assigned to a php variable so i made some modification to bart's patch as follows
so basically it gives all the possible replacement tokens and its values in $data->available_tokens
provided custom field should be last one in the view's field list
For the first row the output is correct, but when it comes to next row the replacement token for custom field will have replica of first field and this get added up again and again consuming all memory if there are many records.
my custom field has following code
and see the output
so when final row is printed its 'phpcode' is too bulky
so if we could prevent the expansion of custom field's replacement token ie 'phpcode' in '$this->get_render_tokens' then all the fields replacement tokens and values will be available in $data
if i made any mistake plz correct me friends
i guess this is what is being discussed in http://drupal.org/node/467190 post #1
Comment #38
fastforward commented#33 - Perfect One(!)line solution for replacement patterns in Value field (markup)! My JavaScript in Views
<a href="#" onclick="document.getElementById('aaa').value = '[bbb]'; return false;">[bbb]</a>works like a charm! Thank You, JoelStein!Comment #39
smira commentedconfirming #33 works like a charm so far.
using it with the popup filter type.
+1 commit me thinks...
Comment #40
deggertsen commentedWonderful! Exactly what I needed. Patch in #33 works!
Comment #41
karljohann commented+1
Comment #42
vasrush commented#33
This is a lifesaver patch.
It has to be in the next dev.
Comment #43
soulfroys+1 for #33
Comment #44
anybody+1 for permanent integration of #33
Comment #45
windmaomao commented#33, once again, this has to be in the next release
Comment #46
iantresman commentedAny chance that #33 can be rolled into the next nightly dev?
Comment #47
osopolarWorks for me too.
Comment #48
deggertsen commentedIt's about time this gets committed...
Comment #49
iantresman commented+1