Closed (works as designed)
Project:
Views (for Drupal 7)
Version:
6.x-2.6
Component:
Views Data
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
11 Aug 2009 at 18:22 UTC
Updated:
11 Aug 2009 at 23:03 UTC
Ii am theming a view and am finding that the content fields are coming out mis-named, and their names change depending on their output order in the Fields area. Here are the fields I'm working with as reported by Theme Information:
When I print_r($vars['row']), I get this -- notice the odd way the node_data fields are named:
stdClass Object
(
[nid] => 18
[node_data_field_store_hours_field_store_hours_value] =>
[node_type] => store
[node_vid] => 306
[node_data_field_store_hours_field_phone_number_value] =>
[node_data_field_store_hours_field_long_description_value] => (data)
[node_data_field_store_hours_field_unit_number_value] => 80
)
If I reorder the fields to put the unit number first, then those node_data fields come out like this instead:
stdClass Object
(
[nid] => 18
[node_data_field_unit_number_field_unit_number_value] => 80
[node_type] => store
[node_vid] => 306
[node_data_field_unit_number_field_store_hours_value] =>
[node_data_field_unit_number_field_phone_number_value] =>
[node_data_field_unit_number_field_long_description_value] => (data)
)
I've searched for a similar issue in the Views and CCK issue queues but haven't found anything. I've disabled all other contrib modules and don't see any change. What else can I try?
Comments
Comment #1
merlinofchaos commentedThe names used in the actual result object are not guaranteed, and never have been, and never will be. In order to prevent collisions, this is a very important distinction.
If you want to know what the actual variable in the result object will be, you can get that information from the handler:
$view->field[$field_id]->field_alias
That is guaranteed to always be correct. $field_id is guaranteed never to change once you've added the field to a view.
Comment #2
markabur commentedthanks, i can certainly set up my view and then not touch the field order when i'm theming... though i'm a bit confused by your explanation.
what's the difference between "names used in the actual result object" (which are not guaranteed), and the "actual variable in the result object"?
is the field naming i just noticed different than it used to be? i have some sites i built a few months ago and the field names weren't smooshed together like they are now.
note that i am seeing field_alias match the field names i'm getting from print_r($vars['row']):
in a preprocessor function, is it possible to get at my long description field using 'field_long_description_value' instead of 'node_data_field_unit_number_field_long_description_value'?
thanks,
-mark
Comment #3
markabur commentedany idea why this works:
print_r($vars['row']->{$vars['view']->field['field_store_hours_value']->field_alias});
but the same thing with this field:
print_r($vars['row']->{$vars['view']->field['field_store_long_description_value']->field_alias})
results in this error?
[11-Aug-2009 13:45:15] PHP Fatal error: Cannot access empty property in [...]/template.php on line 92
'field_store_long_description_value' is the correct id, and 'node_data_field_unit_number_field_long_description_value' seems to be an alias for it, but $vars['view']->field['field_store_long_description_value']->field_alias is null...
i'd like to avoid hard-coding the alias, but it appears to be the only way to get the content if this particular field:
print_r($vars['row']->'node_data_field_unit_number_field_long_description_value')
Comment #4
merlinofchaos commentedfield_long_description_value
vs
field_store_long_description_value
I think the second one is in error.
Comment #5
markabur commenteddoh! thanks.
Comment #6
markabur commentedok, sorry, one more related issue. one of my cck fields is a multiple-select.
if i have the "group multiple values" option turned off, i get the expected alias:
print_r($vars['view']->field['field_credit_cards_value']->field_alias);
result: node_data_field_credit_cards_field_credit_cards_value
but if i have the "group multiple values" option turned on -- which is what i need -- then look what happens:
print_r($vars['view']->field['field_credit_cards_value']->field_alias);
result: node_vid
obviously then when i get the value $vars['row']->node_vid i don't see the credit cards, i see the vid.
you can actually see the problem in my OP -- the credit cards field does not appear in the result object. if i turn group multiple values off, then the credit cards field *does* appear in the result object.
Comment #7
merlinofchaos commentedWhen using group multiple, the values are retrieved through a secondary query. They should be stored somewhere on the object itself at that point, and you'll have to reference them probably with a nid or vid.