You are here

function UpgradePathTaxonomyTestCase::instanceVocabularies in Drupal 7

Retrieve an array mapping allowed vocabulary id to field name for all taxonomy_term_reference fields for which an instance exists for the specified entity type and bundle.

1 call to UpgradePathTaxonomyTestCase::instanceVocabularies()
UpgradePathTaxonomyTestCase::testTaxonomyUpgrade in modules/simpletest/tests/upgrade/upgrade.taxonomy.test
Basic tests for the taxonomy upgrade.

File

modules/simpletest/tests/upgrade/upgrade.taxonomy.test, line 28

Class

UpgradePathTaxonomyTestCase
Test taxonomy upgrades.

Code

function instanceVocabularies($entity_type, $bundle) {
  $instances = array();
  foreach (field_info_instances($entity_type, $bundle) as $instance) {
    $field = field_info_field($instance['field_name']);
    if ($field['type'] == 'taxonomy_term_reference') {
      foreach ($field['settings']['allowed_values'] as $tree) {

        // Prefer valid taxonomy term reference fields for a given vocabulary
        // when they exist.
        if (empty($instances[$tree['vocabulary']]) || $instances[$tree['vocabulary']] == 'taxonomyextra') {
          $instances[$tree['vocabulary']] = $field['field_name'];
        }
      }
    }
  }
  return $instances;
}