Answers.Body: <p>This is definitely possible.  I've done it to have a custom field store a term id, and user selects from a select list of term names...</p>
  
  <p>You need to implement hook_civicrm_customFieldOptions().
  <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_customFieldOptions" rel="nofollow noreferrer">http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_customFieldOptions</a></p>
  
  <p>In this provided example below I am using EntityFieldQuery to fetch all terms of the vocabulary with machine name center. 
  $fieldID is the custom field id</p>
  
  <p>The custom field with ID 4 in my example was configured as an Alphanumeric data type with a Multi-Select widget, but you could use a regular select widget as well.</p>
  
  <p>I hope this gets you started!</p>
  
  <pre><code>function YOURMODULE_civicrm_customFieldOptions( $fieldID, &amp;$options, $detailedFormat = false ) {
      if($fieldID == 4) {
          $center_query = new EntityFieldQuery();
          $center_query-&gt;entityCondition('entity_type', 'taxonomy_term');
          $center_query-&gt;entityCondition('bundle', 'center');
  
          $centers_ids = $center_query-&gt;execute();
  
          $detailed_options = array();
  
          $centers = entity_load('taxonomy_term', array_keys($centers_ids['taxonomy_term']));
  
          foreach($centers as $center) {
            $label = '';
  
            $label .= ' ' . $center-&gt;name;
            if($detailedFormat) {
              $detailed_options[$center-&gt;tid] = array (
                'id' =&gt; $center-&gt;tid,
                'value' =&gt; $center-&gt;tid,
                'label' =&gt; $label,
              );
            }
            else {
              $options[$center-&gt;tid] = $label;
            }
  
          }
  
          if($detailedFormat) {
            $options += $detailed_options;
          }
  
          asort($options);
        }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-04T19:01:23.380Z
Answers.LastActivityDate: 2017-02-04T19:01:23.380Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>Is there any kind of integration between Civi option groups and Drupal taxonomy vocabs? </p>
  
  <p>For instance I'd like to create a Civi custom field with an option group whose options are populated from a Drupal taxonomy. Or vice versa!</p>
  
  <p>Has that ever been acheived? I'd be glad to know if it has. Thanks for your thoughts.</p>
  
Tags: <custom-fields><option>
Title: Drupal taxonomy and Civi option groups integration
ThreadText: # Drupal taxonomy and Civi option groups integration
  
  (Asked by: username_0 on 2017-02-03)
  
  Is there any kind of integration between Civi option groups and Drupal taxonomy vocabs?
  
  For instance I'd like to create a Civi custom field with an option group whose options are populated from a Drupal taxonomy. Or vice versa!
  
  Has that ever been acheived? I'd be glad to know if it has. Thanks for your thoughts.
  
  **Tags:** custom-fields, option
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-04. Score: 4
  
  This is definitely possible.  I've done it to have a custom field store a term id, and user selects from a select list of term names...
  You need to implement hook_civicrm_customFieldOptions().
  http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_customFieldOptions
  In this provided example below I am using EntityFieldQuery to fetch all terms of the vocabulary with machine name center. 
  $fieldID is the custom field id
  The custom field with ID 4 in my example was configured as an Alphanumeric data type with a Multi-Select widget, but you could use a regular select widget as well.
  I hope this gets you started!
  function YOURMODULE_civicrm_customFieldOptions( $fieldID, &$options, $detailedFormat = false ) {
      if($fieldID == 4) {
          $center_query = new EntityFieldQuery();
          $center_query->entityCondition('entity_type', 'taxonomy_term');
          $center_query->entityCondition('bundle', 'center');
  
          $centers_ids = $center_query->execute();
  
          $detailed_options = array();
  
          $centers = entity_load('taxonomy_term', array_keys($centers_ids['taxonomy_term']));
  
          foreach($centers as $center) {
            $label = '';
  
            $label .= ' ' . $center->name;
            if($detailedFormat) {
              $detailed_options[$center->tid] = array (
                'id' => $center->tid,
                'value' => $center->tid,
                'label' => $label,
              );
            }
            else {
              $options[$center->tid] = $label;
            }
  
          }
  
          if($detailedFormat) {
            $options += $detailed_options;
          }
  
          asort($options);
        }
  }
  
  
  ---
  
  