/** * Override Migration::prepare(). * * Set the term parent for heirarchical terms * * @param $term * @param $row */ public function prepare($term, $row) { // Handle og_vocab $vocab_name = $this->bundle; if (!($vocabulary = taxonomy_vocabulary_machine_name_load($vocab_name))) { // Create a new vocabulary $vocabulary = (object) array('name' => 'Meter categories for ' . $row->account_id, 'description' => 'Meter categories for ' . $row->account_id, 'machine_name' => $vocab_name); taxonomy_vocabulary_save($vocabulary); } // Create an OG-vocab and relate new vocabulary with OG. $account_id = $term->account_id['destid1']; $settings = array('cardinality' => 1, 'required' => TRUE); // Loop for all meter content-types and create og-vocabulary. $node_types = node_type_get_types(); foreach ($node_types as $content_type) { if (strpos($content_type->type, '_meter') === FALSE) { // Not a meter type, skip. continue; } $og_vocab = og_vocab_create_og_vocab($vocabulary->vid, 'node', $content_type->type, OG_VOCAB_FIELD, $settings); $og_vocab->save(); } og_vocab_relation_save($vocabulary->vid, 'node', $account_id); // Save vocabulary id. $term->vid = $vocabulary->vid; // Handle parent. $term->name = ucwords(trim($term->name)); $parent = ucwords(trim($row->parent)); $parent_term = taxonomy_get_term_by_name($parent, $vocab_name); $parent_term = reset($parent_term); if ($parent_term) { $term->parent = $parent_term->tid; } }
/** * @param $bundle * The content type. * @param $vocabulary * The vocabulary name. */ public static function BindContentToVocab($bundle, $vocabulary) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'taxonomy_vocabulary')->propertyCondition('name', $vocabulary)->execute(); if (empty($result['taxonomy_vocabulary'])) { return; } $vid = reset($result['taxonomy_vocabulary'])->vid; og_vocab_create_og_vocab($vid, 'node', $bundle)->save(); }