Closed (fixed)
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
20 Jan 2012 at 09:42 UTC
Updated:
18 Apr 2013 at 14:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Juryiel commentedI was able to figure this out using the Devel module. I used the dsm() command, as dsm($data) in the php code of the view and found that if you add the field collection field with name NameOfField to the view with teh appropriate field collection relationship, then its data is stored in:
$data->field_field_NameOfField[0]['raw']['value']
and this will return the correct value in the PHP box. I'm not sure if there's a better way, or if there are issues with this for different field types (I was using booleans here) so I'll mark this as 'needs review' but it works for my purposes.
Comment #2
tim.plunkettThat seems fine.
Comment #3
directory1182 commentedI receive the following error:
Comment #5
isramv commentedComment #1 worked for me thanks
Comment #6
ChrisValentine commentedI can only get the solution in #1 to give a single value. I see mention of setting a relationship but if I add one, I get duplicates of my containing records.
My collection is called: field_hydro_prop_readings
It contains a single float numeric field called: field_river_hydroprop_time
I will have up to three of these per containing content type record - I want to extract and use all of those values in a Global: PHP field in a view.
The array dump that comes back from $data->field_field_hydro_prop_readings seems absurdly complex.
$data->field_field_river_hydroprop_time[0]['raw']['value']; gives me nothing.
The annoying thing is that even without a relationship, if I add "field_hydro_prop_readings" as a field in my table, I get all three correct values of field_river_hydroprop_time for that record (admittedly with some other formatting stuff that I can't get rid of completely) so I know the data is there - I just need to grab the values in PHP (so I can do an average).
Comment #7
pmol123 commentedI have two work arounds for this type of problem by the Drupal 7 Views PHP field/filter not working.
(1) I added a computed field to the bundle and do my calculation there.
For example, I needed to take an action by whether a Unix timestamp was set (and > 0) OR not set. This was kinda link using the NULL and NOT NULL in the pre-drupal SQL days of build web apps.
(2) Use Views Templates and over ride the "display", "row" and "fields", then add my code that is needed on the output.
For example, I was storing a URL in a field. I needed to change a url-parameter before another process would load it after calling the view. I found that over riding the views template for that field , making the one line (str_replace) command worked great.
Note: Some changes, executions won't display in the preview or before saving.
Patrick