diff options
author | Jennifer Hodgdon <yahgrp@poplarware.com> | 2013-06-20 07:20:12 -0700 |
---|---|---|
committer | Jennifer Hodgdon <yahgrp@poplarware.com> | 2013-06-20 07:20:12 -0700 |
commit | c23de5265f5f9d9652192d4773ced682caaa47b6 (patch) | |
tree | 239d173a061dd3c5b74ef66860e9b06d8ce963da /modules/taxonomy | |
parent | 0a14ec94181af3fcbb9ad6d9fd4b7e72dc850c7e (diff) | |
download | brdo-c23de5265f5f9d9652192d4773ced682caaa47b6.tar.gz brdo-c23de5265f5f9d9652192d4773ced682caaa47b6.tar.bz2 |
Issue #1831540 by orb, sergeypavlenko, Berdir, andypost, podarok, cam8001, Gaelan: Rewrite examples for taxonomy hooks in taxonomy.api.php
Diffstat (limited to 'modules/taxonomy')
-rw-r--r-- | modules/taxonomy/taxonomy.api.php | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/modules/taxonomy/taxonomy.api.php b/modules/taxonomy/taxonomy.api.php index 5667eb96d..b9c23dbfe 100644 --- a/modules/taxonomy/taxonomy.api.php +++ b/modules/taxonomy/taxonomy.api.php @@ -20,12 +20,15 @@ * An array of taxonomy vocabulary objects. */ function hook_taxonomy_vocabulary_load($vocabularies) { - foreach ($vocabularies as $vocabulary) { - $vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE); + $result = db_select('mytable', 'm') + ->fields('m', array('vid', 'foo')) + ->condition('m.vid', array_keys($vocabularies), 'IN') + ->execute(); + foreach ($result as $record) { + $vocabularies[$record->vid]->foo = $record->foo; } } - /** * Act on taxonomy vocabularies before they are saved. * @@ -49,8 +52,8 @@ function hook_taxonomy_vocabulary_presave($vocabulary) { * A taxonomy vocabulary object. */ function hook_taxonomy_vocabulary_insert($vocabulary) { - if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE); + if ($vocabulary->machine_name == 'my_vocabulary') { + $vocabulary->weight = 100; } } @@ -63,10 +66,10 @@ function hook_taxonomy_vocabulary_insert($vocabulary) { * A taxonomy vocabulary object. */ function hook_taxonomy_vocabulary_update($vocabulary) { - $status = $vocabulary->synonyms ? TRUE : FALSE; - if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status); - } + db_update('mytable') + ->fields(array('foo' => $vocabulary->foo)) + ->condition('vid', $vocabulary->vid) + ->execute(); } /** @@ -79,9 +82,9 @@ function hook_taxonomy_vocabulary_update($vocabulary) { * A taxonomy vocabulary object. */ function hook_taxonomy_vocabulary_delete($vocabulary) { - if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { - variable_del('taxonomy_' . $vocabulary->vid . '_synonyms'); - } + db_delete('mytable') + ->condition('vid', $vocabulary->vid) + ->execute(); } /** @@ -101,7 +104,10 @@ function hook_taxonomy_vocabulary_delete($vocabulary) { * An array of term objects, indexed by tid. */ function hook_taxonomy_term_load($terms) { - $result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms))); + $result = db_select('mytable', 'm') + ->fields('m', array('tid', 'foo')) + ->condition('m.tid', array_keys($terms), 'IN') + ->execute(); foreach ($result as $record) { $terms[$record->tid]->foo = $record->foo; } @@ -130,18 +136,12 @@ function hook_taxonomy_term_presave($term) { * A taxonomy term object. */ function hook_taxonomy_term_insert($term) { - if (!empty($term->synonyms)) { - foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { - if ($synonym) { - db_insert('taxonomy_term_synonym') - ->fields(array( - 'tid' => $term->tid, - 'name' => rtrim($synonym), - )) - ->execute(); - } - } - } + db_insert('mytable') + ->fields(array( + 'tid' => $term->tid, + 'foo' => $term->foo, + )) + ->execute(); } /** @@ -153,19 +153,10 @@ function hook_taxonomy_term_insert($term) { * A taxonomy term object. */ function hook_taxonomy_term_update($term) { - hook_taxonomy_term_delete($term); - if (!empty($term->synonyms)) { - foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { - if ($synonym) { - db_insert('taxonomy_term_synonym') - ->fields(array( - 'tid' => $term->tid, - 'name' => rtrim($synonym), - )) - ->execute(); - } - } - } + db_update('mytable') + ->fields(array('foo' => $term->foo)) + ->condition('tid', $term->tid) + ->execute(); } /** @@ -178,7 +169,9 @@ function hook_taxonomy_term_update($term) { * A taxonomy term object. */ function hook_taxonomy_term_delete($term) { - db_delete('term_synoynm')->condition('tid', $term->tid)->execute(); + db_delete('mytable') + ->condition('tid', $term->tid) + ->execute(); } /** |