Active
Project:
Computed Field
Version:
7.x-1.0-beta1
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 Apr 2012 at 07:24 UTC
Updated:
24 Oct 2013 at 08:27 UTC
Jump to comment: Most recent
Comments
Comment #1
deggertsen commentedI'm trying to get help with this as well. Did you ever figure it out?
Comment #2
deggertsen commentedI was able to do what I was trying to do with this code.
In the computed code I did this. In my use case I have a node with the title as a last name and another field with the first name. I wanted a hidden field that I could use in views and faceted search that would automatically combine the two. It took me awhile to figure out how to get the title (or last name) to display correctly, but this did it. Notice the ' ' for the space in between the two values.
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_speaker_first_name'))) . ' ' . $entity->title;Then, in order to display HTML special characters such as &, I put this function into a custom module.
Hope that helps someone.
Comment #3
boabjohn commentedThanks for the input @deggersten but this is not our usecase or solution envelope (ie, no use of custom module should be required for such a trivial exercise).
Could anyone please spare a moment to drop a line of PHP on this issue?
Thanks indeed.
Comment #4
deggertsen commentedThe only reason the custom module was needed is because I didn't want special characters coming out as
$amp;and the like. If you don't care about that no custom module is needed.Comment #5
rudyard55 commentedSo...
What's the answer?
To not require a custom module, what gets put in the "Display Code (PHP)" box?
Comment #6
boabjohn commentedGood questyion! I've been doing a pythin course over at codecademy...maybe I should dip into the PHP offering and see if there's a quick answer. It has to be totally trivial (for those who know what they are doing!) but fo rthe rest of us it's a showstopper. That's why I wanted to get it into the list of code snippets. That was 9 months ago! still no code. sigh.
Comment #7
rudyard55 commentedHere's what I've figured out...
In the code section use
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_lastname'))) . ' ' . array_pop(array_pop(field_get_items($entity_type, $entity, 'field_firstname')));and in the display section use:
$display_output = $entity_field_item['value'];My scenario required a little different code because my second field came from a term reference field. But I believe the above will work in your specific scenario.
Comment #8
MatthijsG commentedThis worked for me. When you're looking for the correct fieldname, use the name used in the row 'system name' on the page admin/structure/types/manage/YOURCONTENTTYPE/fields.
Now find out how to use the date to combine with the text ..
Comment #9
DrupalRanger commentedI know this post is old but the above solution throws a non critical error. The below solution I found to work.
Computed Code
$field_a = field_get_items($entity_type, $entity, 'field_first_name');
$field_b = field_get_items($entity_type, $entity, 'field_last_name');
$entity_field[0]['value'] = $field_a[0]['value'] . " " . $field_b[0]['value'];
Display Code
$display_output = $entity_field_item['value'];