diff --git a/gmap_taxonomy.install b/gmap_taxonomy.install index 02e02d4..5acae6f 100644 --- a/gmap_taxonomy.install +++ b/gmap_taxonomy.install @@ -91,6 +91,41 @@ function gmap_taxonomy_update_6001() { } /** + * Use vocabularies machine names instead of vids. + */ +function gmap_taxonomy_update_6002() { + $enabled_vocabularies = variable_get('gmap_taxonomy_vocabs', array()); + $enabled_vocabularies = array_keys(array_filter($enabled_vocabularies)); + + $result = array(); + foreach ($enabled_vocabularies as $vid) { + $vocabulary = taxonomy_vocabulary_load($vid); + if ($vocabulary) { + $result[$vocabulary->machine_name] = TRUE; + } + } + + // Save result + variable_set('gmap_taxonomy_vocabs', $result); +} + +/** + * Use vocabularies machine names instead of vids. + */ +function gmap_taxonomy_update_7201() { + $enabled_vocabularies = variable_get('gmap_taxonomy_vocabs', array()); + $vocabularies = taxonomy_vocabulary_load_multiple(array_keys(array_filter($enabled_vocabularies))); + + $result = array(); + foreach ($vocabularies as $vocabulary) { + $result[$vocabulary->machine_name] = TRUE; + } + + // Save result + variable_set('gmap_taxonomy_vocabs', $result); +} + +/** * Rebuild {gmap_taxonomy_node} again. */ /* diff --git a/gmap_taxonomy.module b/gmap_taxonomy.module index dd06ed3..0ca43c5 100644 --- a/gmap_taxonomy.module +++ b/gmap_taxonomy.module @@ -17,23 +17,17 @@ function gmap_taxonomy_form_alter(&$form, &$form_state, $form_id) { '#title' => t('GMap markers'), ); $vid = isset($form['vid']) ? $form['vid']['#value'] : -1; - $temp = variable_get('gmap_taxonomy_vocabs', array()); - if (!isset($temp[$vid])) { - $temp[$vid] = 0; - } $form['gmap_taxonomy']['gmap_taxonomy_enable'] = array( '#type' => 'checkbox', '#title' => t('Enable'), '#description' => t('Enable choosing a marker for terms in this vocabulary.'), - '#default_value' => $temp[$vid], + '#default_value' => gmap_taxonomy_vocabulary_is_enabled($vid), ); } // @@@ Why does this get called up on delete? if ($form_id == 'taxonomy_form_term' && empty($form['confirm']['#value'])) { - $vid = $form['#vocabulary']->vid; $term = (object)$form['#term']; - $vocs = variable_get('gmap_taxonomy_vocabs', array()); - if (isset($vocs[$vid]) && $vocs[$vid]) { + if (gmap_taxonomy_vocabulary_is_enabled($form['#vocabulary'])) { $temp = ''; if (!empty($term->tid)) { if ($t = db_query('SELECT marker FROM {gmap_taxonomy_term} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField()) { @@ -84,7 +78,7 @@ function gmap_taxonomy_taxonomy_vocabulary_insert($vocabulary) { function gmap_taxonomy_taxonomy_vocabulary_update($vocabulary) { if (isset($vocabulary->gmap_taxonomy_enable)) { $status = variable_get('gmap_taxonomy_vocabs', array()); - $status[$vocabulary->vid] = $vocabulary->gmap_taxonomy_enable; + $status[$vocabulary->machine_name] = $vocabulary->gmap_taxonomy_enable; variable_set('gmap_taxonomy_vocabs', $status); } } @@ -94,7 +88,7 @@ function gmap_taxonomy_taxonomy_vocabulary_update($vocabulary) { */ function gmap_taxonomy_taxonomy_vocabulary_delete($vocabulary) { $status = variable_get('gmap_taxonomy_vocabs', array()); - unset($status[$vocabulary->vid]); + unset($status[$vocabulary->machine_name]); variable_set('gmap_taxonomy_vocabs', $status); } @@ -109,8 +103,7 @@ function gmap_taxonomy_taxonomy_term_insert($term) { * Implement hook_taxonomy_term_update(). */ function gmap_taxonomy_taxonomy_term_update($term) { - $vocabs = variable_get('gmap_taxonomy_vocabs', array()); - if (isset($vocabs[$term->vid]) && $vocabs[$term->vid]) { + if (gmap_taxonomy_vocabulary_is_enabled($term->vid)) { db_delete('gmap_taxonomy_term') ->condition('tid', $term->tid) ->execute(); @@ -215,6 +208,26 @@ function gmap_taxonomy_node_revision_delete($node) { */ /** + * Check if gmap taxonomy is enabled for the given vocabulary + * + * @param $vocabulary + * The vocabulary to check. Entire object and vid are allowed. + * @return bool + * TRUE if the vocabulary is enabled + */ +function gmap_taxonomy_vocabulary_is_enabled($vocabulary) { + if (!is_object($vocabulary)) { + $vocabulary = taxonomy_vocabulary_load($vocabulary); + } + + $enabled_vocabularies = variable_get('gmap_taxonomy_vocabs', array()); + + return $vocabulary + && isset($enabled_vocabularies[$vocabulary->machine_name]) + && $enabled_vocabularies[$vocabulary->machine_name]; +} + +/** * Get all gmap taxonomy markers * Helper function to return cached version of gmap taxonomy markers from the database * @return