antonyms = taxonomytest_get_antonyms($term->tid); } /** * Implementation of hook_taxonomy_term_save(). */ function taxonomytest_taxonomy_term_save($term, $form_values) { taxonomytest_taxonomy_term_delete($term); if (!empty($form_values['antonyms'])) { foreach (explode ("\n", str_replace("\r", '', $form_values['antonyms'])) as $antonym) { if ($antonym) { db_insert('term_antonym') ->fields(array( 'tid' => $form_values['tid'], 'name' => rtrim($antonym), )) ->execute(); } } } } /** * Implementation of hook_taxonomy_term_delete(). */ function taxonomytest_taxonomy_term_delete($term) { db_delete('term_antonym')->condition('tid', $term->tid)->execute(); } /** * Implementation of hook_form_alter(). */ function taxonomytest_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'taxonomy_form_term') { $form['advanced']['antonyms'] = array( '#type' => 'textarea', '#title' => t('Antonyms'), '#default_value' => implode("\n", taxonomytest_get_antonyms($form['#term']['tid'])), '#description' => t('Antonyms of this term, one antonym per line.')); } } /** * Return an array of antonyms of the given term ID. */ function taxonomytest_get_antonyms($tid) { if ($tid) { $antonyms = array(); $result = db_query('SELECT name FROM {term_antonym} WHERE tid = :tid', array(':tid' => $tid)); foreach($result AS $antonym) { $antonyms[] = $antonym->name; } return $antonyms; } else { return FALSE; } }