Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I have a vocabulary called "Style Colors". And in my nodes, I have a field referencing it called "field_stylecolor".
When I have,
$tid= $entity->field_stylecolor['und'][0];
$entity_field[0]['value'] = $tid;
in my computed field, it returns "34", which is the tid of a color (e.g. "red").
Now, I want the computed field to return the (string) term name of the color (i.e. "red"), so I type,
$tid = $entity->field_stylecolor['und'][0];
$term = taxonomy_term_load($tid);
$entity_field[0]['value'] = $term->name;
in computed field, but now it doesn't return anything.
What am I doing wrong here?
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedTry this..
Comment #2
doublejosh CreditAttribution: doublejosh commentedDon't think this is Computed Field's fault. I've found the same problem with
taxonomy_term_load
elsewhere. In a custom menu callback I can access a profile field and get the tid, but get nothing from the taxonomy load function.WTF!
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedThe code I posted above seems to work in Computed Field. In regular Drupal files I use something like this:
Comment #4
dos360 CreditAttribution: dos360 commentedKline's code is worked for me. Here is my example where $coll stands the collection name stored as taxonomy terms and $number denotes the individual document's id.
Comment #5
kaizerking CreditAttribution: kaizerking commentedI have profile2 profile,
which has the filed collection field field_resume_xp, unlimted values,this field collection field has a field called 'field_duration' this value is populated with computed field
This field collection also has a term reference field with two terms ]term_1 and term_2
Now I have 2 fields in profile2 profile "field_total_duration_term1" and "field_total_duration_term2" I want the sum of all the "field_duration" values for term_1 in "field_total_duration_term1" field and sum of all the "field_duration" values for term|_2 in "field_total_duration_term2" field
Simply I want sum of term1 durations and sum of term2 durations separately computed and stored
how to get this?
without applying the term filter this code works very nicely to get sum of field durations probably some one can help me with filetering by term
Comment #6
kaizerking CreditAttribution: kaizerking commentedWhat am I doin wrong in this code ?
Comment #7
matthewgann CreditAttribution: matthewgann commentedI also can't get taxonomy_term_load function to work within computed field. Trying to grab field data from a term from the author.
Any idea on a workaround or a fix?