You are here

protected function OgVocabMigrate::addOgVocab in OG Vocabulary 7

Helper function to add the OG-vocab entity.

Parameters

$vid: The vocabulary ID related to the group.

$field_name: The taxonomy term reference field, that needs to be converted to and OG-vocab entity.

1 call to OgVocabMigrate::addOgVocab()
OgVocabMigrate::prepareRow in includes/migrate/og_vocab.migrate.inc
Default implementation of prepareRow(). This method is called from the source plugin upon first pulling the raw data from the source.

File

includes/migrate/og_vocab.migrate.inc, line 132
Migrate plugin to populate the OG vocabulary field by the term references.

Class

OgVocabMigrate
@file Migrate plugin to populate the OG vocabulary field by the term references.

Code

protected function addOgVocab($vid, $field_name) {

  // Cache the vocabulary ID and field names that were queried to avoid
  // hitting the DB multiple times.
  $cache =& drupal_static(__METHOD__, array());
  $bundle = $this->bundle;
  if (isset($cache[$bundle][$field_name][$vid])) {
    return;
  }
  $cache[$bundle][$field_name][$vid] = TRUE;
  if (!og_vocab_load_og_vocab($vid, 'node', $bundle)) {
    $field = field_info_field($field_name);
    $instance = field_info_instance('node', $field_name, $bundle);
    $settings = array(
      'required' => $instance['required'],
      'widget_type' => $instance['widget']['type'] == 'options_select' ? 'options_select' : 'entityreference_autocomplete_tags',
      'cardinality' => $field['cardinality'],
    );
    $og_vocab = og_vocab_create_og_vocab($vid, 'node', $bundle, $settings);
    $og_vocab
      ->save();
  }
}