2008-11-02 14:42:45 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Test module for Taxonomy hooks and functions not used in core.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_taxonomy_term_load().
|
2008-11-02 14:42:45 +00:00
|
|
|
*/
|
2009-12-04 15:54:37 +00:00
|
|
|
function taxonomy_test_taxonomy_term_load($terms) {
|
2008-12-05 22:18:46 +00:00
|
|
|
foreach ($terms as $term) {
|
2009-08-03 20:19:29 +00:00
|
|
|
$antonym = taxonomy_test_get_antonym($term->tid);
|
|
|
|
if ($antonym) {
|
|
|
|
$term->antonym = $antonym;
|
|
|
|
}
|
2008-12-05 22:18:46 +00:00
|
|
|
}
|
2008-11-02 14:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_taxonomy_term_insert().
|
2008-11-02 14:42:45 +00:00
|
|
|
*/
|
2008-11-02 17:46:47 +00:00
|
|
|
function taxonomy_test_taxonomy_term_insert($term) {
|
2009-08-03 20:19:29 +00:00
|
|
|
if (!empty($term->antonym)) {
|
|
|
|
db_insert('taxonomy_term_antonym')
|
|
|
|
->fields(array(
|
|
|
|
'tid' => $term->tid,
|
|
|
|
'name' => trim($term->antonym)
|
|
|
|
))
|
|
|
|
->execute();
|
2008-11-02 17:46:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_taxonomy_term_update().
|
2008-11-02 17:46:47 +00:00
|
|
|
*/
|
|
|
|
function taxonomy_test_taxonomy_term_update($term) {
|
2009-08-03 20:19:29 +00:00
|
|
|
if (!empty($term->antonym)) {
|
|
|
|
db_merge('taxonomy_term_antonym')
|
|
|
|
->key(array('tid' => $term->tid))
|
|
|
|
->fields(array(
|
|
|
|
'name' => trim($term->antonym)
|
|
|
|
))
|
|
|
|
->execute();
|
2008-11-02 14:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_taxonomy_term_delete().
|
2008-11-02 14:42:45 +00:00
|
|
|
*/
|
|
|
|
function taxonomy_test_taxonomy_term_delete($term) {
|
2009-08-03 20:19:29 +00:00
|
|
|
db_delete('taxonomy_term_antonym')
|
2009-05-30 11:17:32 +00:00
|
|
|
->condition('tid', $term->tid)
|
|
|
|
->execute();
|
2008-11-02 14:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_form_alter().
|
2008-11-02 14:42:45 +00:00
|
|
|
*/
|
|
|
|
function taxonomy_test_form_alter(&$form, $form_state, $form_id) {
|
|
|
|
if ($form_id == 'taxonomy_form_term') {
|
2009-08-03 20:19:29 +00:00
|
|
|
$antonym = taxonomy_test_get_antonym($form['#term']['tid']);
|
|
|
|
$form['advanced']['antonym'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('Antonym'),
|
|
|
|
'#default_value' => !empty($antonym) ? $antonym : '',
|
|
|
|
'#description' => t('Antonym of this term.')
|
2008-11-02 14:42:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 20:19:29 +00:00
|
|
|
* Return the antonym of the given term ID.
|
2008-11-02 14:42:45 +00:00
|
|
|
*/
|
2009-08-03 20:19:29 +00:00
|
|
|
function taxonomy_test_get_antonym($tid) {
|
|
|
|
return db_select('taxonomy_term_antonym', 'ta')
|
|
|
|
->fields('ta', array('name'))
|
|
|
|
->condition('tid', $tid)
|
|
|
|
->execute()
|
|
|
|
->fetchField();
|
2008-11-02 14:42:45 +00:00
|
|
|
}
|