Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

7 - Populating select list from a taxonomy term field

Source Link
dharma
  • 342
  • 1
  • 9

7 - Populating select list from a taxonomy term field

I'm trying to populate a select list dynamically by pulling its values from a taxonomy term field linked to the current-user account. Just to clarify, below function is a hook defined by a module that came with a custom installation profile. It is basically used to create fields on a specific form. So, my custom module has-

function some_function_attributes() {


      global $user;
      $user_fields = user_load($user->uid);
      $termid = $user_fields->field_user_organization['und']['0']['tid'];
      $taxonomy_term = taxonomy_term_load($termid);
      //dsm($taxonomy_term);
      $options = field_get_items('taxonomy_term', $taxonomy_term, 'field_org_environment','select');
      dsm($options);
      return array(
        'environment' => array(
        'type' => 'select',
        'options' => $options,
        'name' => t('Environment'),
        )
      );
    }

Allowed values in the field (for this user)-

E1|Env1

E2|Env2


Here's the devel screenshot for dsm($options); enter image description here

So, its populating the right field but not in the way it should.


Actual form element looks like this- enter image description here

Currently, its just returning the array and I can't figure out what I missed. Been banging my head to the wall for this- How would I populate Env1 and Env2 in this select-list ?