You are here

function og_vocab_load_og_vocab in OG Vocabulary 7

Get OG vocabulary settings by vocabulary ID.

3 calls to og_vocab_load_og_vocab()
OgVocabMigrate::addOgVocab in includes/migrate/og_vocab.migrate.inc
Helper function to add the OG-vocab entity.
og_vocab_field_widget_form in ./og_vocab.module
Implements hook_field_widget_form().
og_vocab_form_taxonomy_form_vocabulary_alter in ./og_vocab.module
Implements hook_form_FORM-ID_alter().

File

./og_vocab.module, line 299
Give each group its own system controlled vocabularies.

Code

function og_vocab_load_og_vocab($vid, $entity_type, $bundle, $field_name = NULL, $defaults = FALSE) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'og_vocab')
    ->propertyCondition('vid', $vid)
    ->propertyCondition('entity_type', $entity_type)
    ->propertyCondition('bundle', $bundle)
    ->range(0, 1);
  if (!empty($field_name)) {
    $query
      ->propertyCondition('field_name', $field_name);
  }
  $result = $query
    ->execute();
  if (empty($result['og_vocab'])) {
    if (!$defaults) {
      return;
    }
    if (empty($field_name)) {

      // Get the field name from the bundle, or default to OG_VOCAB_FIELD.
      $field_names = og_vocab_get_og_vocab_fields($entity_type, $bundle);
      $field_name = !empty($field_names) ? key($field_names) : OG_VOCAB_FIELD;
    }
    return og_vocab_create_og_vocab($vid, $entity_type, $bundle, $field_name);
  }
  $id = key($result['og_vocab']);
  return entity_load_single('og_vocab', $id);
}