Closed (duplicate)
Project:
Views PHP
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
14 Feb 2011 at 17:31 UTC
Updated:
22 Oct 2015 at 18:47 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
casey commentedSomething like:
Or maybe even (when does a field contain data for multiple languages?):
Or
Any ideas/preferences?
Comment #2
johnvThe shorter, the better :-)
With D7 you can translate a node per field, so a number-field will only have the untranslated version/original languge; a textfield will be available in 3 languages. I do not know how this is 'published' in the $data, though.
I would the prefer $row->${field_name}[0]['value']; (I skipped the '_field'-part). Is it possible to have the language as an option, e.g. $row->${field_name}['en'][0]['value'] would work, too?
I have three alternatives:
- use the conventions from the css-files, e.g. views-view-field.tpl.php; ideally you can publish existing data, or 'mimic' it.
- use tokens/ replacement patterns instead of own variables.
- mimic the Views-field 'Global: Math expression'. I suppose it is from Views3 itself. I uses tokens/replacements patterns like: [entity_id_5] . I don't like the unclear name of this, but using Views, I'll have to get used to it.
Comment #3
marta_yo commentedComment #4
robidigital commentedComment #5
FreeFox commented+1
Comment #6
molave commentedsubscribe
Comment #7
farald commentedSubscribe:)
Comment #8
lightstring commentedSubscribing
Comment #9
gillesv commentedSubscribing
Comment #10
johnvCasey cannot provide more data as long as Views isn't passing it through..
FYI, Issue #1063418: views_get_view_result drupal 7 returns "node" for fields gives some background and tips from the Views-guys.
Comment #11
akagroundhog commentedSubscribing.
Now we have to use
$data->_field_data['nid']['entity']->my_field['en'][0]['value']or$data->_field_data['nid']['entity']->my_field['en'][0]['safe_value']to get the field value. Plus, this code works only in the "Output code" section.$row->my_field['en'][0]['value']looks definitely better.Comment #12
TripX commentedSubscribe
Comment #13
sachbearbeiter commentedsubscribe
Comment #14
rv0 commentedsubscribe
Comment #15
casey commentedJippii, we have a views_handler#post_execute() now. I can fix this now. Hold tight.
Comment #16
guybedford commentedDoes hold tight mean a week or a month?
Would really appreciate so I can know whether I should take this advice or not!!
(Specifically in relation to this bug, which may or may not be a duplicate of this - http://drupal.org/node/1140896)
Comment #17
geerlingguy commentedSubscribing from #1140896: Variable $row does not contain correct values ($data->_field_data does) - right now, for certain fields, I need to access the information inside the $data object, which is only available properly in the output field. It feels hackish to do everything inside that field...
Comment #18
carlos.macao commentedsubscribe
Comment #19
ealtman commentedsubscribe
Comment #20
annikaC commentedsubscribe
Comment #21
kenianbei commented+1
Comment #22
jayhariani commentedSub.
Comment #23
guile2912 commentedsubscibing.
Unfortunatly php filtering is quite useless without that.
I am using a huggly hack to get around this : put the params in the title and hide it, but at least I can access title content in the php filter.
*ashamed*
Comment #24
pjcard commentedsub
Comment #25
timtunbridge commentedI am posting this as it may help other non-coders like myself.
I arrived here as a result of not being able to reference fields using the notation (for example) $row->field_client. This is despite it being listed under available variables (see Available Variables screenshot). The workaround to this is elsewhere in these threads for which I am hugely grateful, but it wasn't readily apparent to me how to make this work in my situation. Here is what I did ...
I started by trying to find out the internal names of everything in my view - for this I firstly entered the following into the Output code field:
This gave me a rather scary result at first but what I needed was in there (see Output Data screenshot). I have always struggled with how to read these types of results but eventually I was able to deduce that the notation I needed to reference my Client field was:
This returns the value of the Client field which in the case of the screenshot example would be ABB Grain.
Hope this helps someone. If there is a better way of achieving the same then please do share this.
Tim
Comment #26
oobie11 commentedI was trying to use the suggestion in #25, but it was not working. I hd to make the quotations double instead of single. Also,
print var_export($data, TRUE);does not work and gives an ajax error. I had to use "var_dump" instead. But looking at this did not help me, considering I had no idea what I was looking at.Comment #27
partyp commentedThanks to #25 and #26 I was able to find my variable as well. For me I ended up getting the variable with the exact same code as
$data->_field_data['nid']['entity']->field_client['und'][0]['value'];but I replaced the "field_client" part with my custom field.
Comment #28
goldlilys commented#27, that long line works, but it's not completely a fix to why we can't just call $row->fieldname without all that hassle. Because that would make the "Available variables" for this module useless.
Yup, the shorter the better.
Comment #29
trevorkjorlien commentedI've followed the instructions for #25 on some fields that are integers and text, and it's worked great! Thanks.
My problem now is that I want to print the values of a term reference field. I've made a taxonomy with a few terms a user can choose, and used a term reference to access them in my content type. The field is called "PV", so my output code looks like:
Following the same steps above in #25, the values don't appear. It just comes up blank. Any idea on how to get them to print? (Also, I know that I can simply add them in the usual Views way, but I need to do something a bit more complex, and I think this is one of the first steps).
Comment #30
ardnet commentedsubscribed
Comment #31
johnvI t might have been solved by Views itself: since views 7.x-3.0-rc1 #1192186: views 7.x-3.0-rc1 , the following function exists:
I now used this (somewhere else, not in Views PHP yet):
Comment #32
mmilo commentedI ran into this problem too, and there are alot of duplicate issues.
Using #1140896: Variable $row does not contain correct values ($data->_field_data does) as the main one.
Comment #33
mmilo commentedComment #34
arekanderu commentedsubscribe
Comment #35
break9 commentedthis worked for me BUT**** it only woks if you use the "Output code". Will not work in the "Value code" section.
Comment #36
iwerksom commentedThe solution in #25 also works for term reference fields. Just beware that you should change the code accordingly. It is not always you should write ['value'] at the end.
My field was named tags and the code that worked:
If you can get it to work. Then look at the output data as mentioned in #25. The picture in the post marks what lines you should be looking for.
Comment #37
mxh commentedWhen you want to use the Value Code field section 'the more proper' way, I'd recommend to load your needed field data by using field_get_items() provided by Field API or with field_extract_value() provided by field_extract module.
Comment #38
Todd Young commentedHave we accepted the workaround as the only option here? Discussion seems to have tapered off...
Comment #39
Todd Young commented*ping*
Comment #40
pipep commented#35 does the trick for me on D7
Comment #41
jordan8037310 commented#25 saved me a lot of time, thanks timtunbridge!
note for people struggling with views that aren't nodes, make sure that you change nid to the appropriate referral in the array. I was working with profiles so i had to use pid.
Cheers
Comment #42
joegl commentedHaving the same issue as #35. The $data object is not getting set in the "Value Code" section which is required for PHP sorting.