summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.module14
-rw-r--r--modules/taxonomy/taxonomy.test17
-rw-r--r--modules/taxonomy/taxonomy.tokens.inc10
3 files changed, 31 insertions, 10 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index c9212550c..f279f1c44 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -493,25 +493,24 @@ function taxonomy_term_save($term) {
module_invoke_all('taxonomy_term_presave', $term);
if (empty($term->tid)) {
+ $op = 'insert';
$status = drupal_write_record('taxonomy_term_data', $term);
field_attach_insert('taxonomy_term', $term);
- module_invoke_all('taxonomy_term_insert', $term);
- module_invoke_all('entity_insert', $term, 'taxonomy_term');
if (!isset($term->parent)) {
$term->parent = array(0);
}
}
else {
+ $op = 'update';
$status = drupal_write_record('taxonomy_term_data', $term, 'tid');
field_attach_update('taxonomy_term', $term);
- module_invoke_all('taxonomy_term_update', $term);
- module_invoke_all('entity_update', $term, 'taxonomy_term');
if (isset($term->parent)) {
db_delete('taxonomy_term_hierarchy')
->condition('tid', $term->tid)
->execute();
}
}
+
if (isset($term->parent)) {
if (!is_array($term->parent)) {
$term->parent = array($term->parent);
@@ -536,8 +535,14 @@ function taxonomy_term_save($term) {
}
$query->execute();
}
+
+ // Reset the taxonomy term static variables.
taxonomy_terms_static_reset();
+ // Invoke the taxonomy hooks.
+ module_invoke_all("taxonomy_term_$op", $term);
+ module_invoke_all("entity_$op", $term, 'taxonomy_term');
+
return $status;
}
@@ -675,6 +680,7 @@ function taxonomy_terms_static_reset() {
drupal_static_reset('taxonomy_term_count_nodes');
drupal_static_reset('taxonomy_get_tree');
drupal_static_reset('taxonomy_get_parents');
+ drupal_static_reset('taxonomy_get_parents_all');
drupal_static_reset('taxonomy_get_children');
entity_get_controller('taxonomy_term')->resetCache();
}
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index adda2fa3a..a7c922b7f 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -1005,7 +1005,22 @@ class TaxonomyTokenReplaceTestCase extends TaxonomyWebTestCase {
$edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->tid;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- // Generate and test sanitized tokens.
+ // Generate and test sanitized tokens for term1.
+ $tests = array();
+ $tests['[term:tid]'] = $term1->tid;
+ $tests['[term:name]'] = check_plain($term1->name);
+ $tests['[term:description]'] = check_markup($term1->description, $term1->format);
+ $tests['[term:url]'] = url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE));
+ $tests['[term:node-count]'] = 0;
+ $tests['[term:parent:name]'] = '[term:parent:name]';
+ $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('term' => $term1), array('language' => $language));
+ $this->assertFalse(strcmp($output, $expected), t('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
+ }
+
+ // Generate and test sanitized tokens for term2.
$tests = array();
$tests['[term:tid]'] = $term2->tid;
$tests['[term:name]'] = check_plain($term2->name);
diff --git a/modules/taxonomy/taxonomy.tokens.inc b/modules/taxonomy/taxonomy.tokens.inc
index 97a62901b..21baca7e0 100644
--- a/modules/taxonomy/taxonomy.tokens.inc
+++ b/modules/taxonomy/taxonomy.tokens.inc
@@ -128,9 +128,10 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'parent':
- $parents = taxonomy_get_parents($term->tid);
- $parent = array_pop($parents);
- $replacements[$original] = check_plain($parent->name);
+ if ($parents = taxonomy_get_parents($term->tid)) {
+ $parent = array_pop($parents);
+ $replacements[$original] = check_plain($parent->name);
+ }
break;
}
}
@@ -140,8 +141,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
$replacements += token_generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options);
}
- if ($vocabulary_tokens = token_find_with_prefix($tokens, 'parent')) {
- $parents = taxonomy_get_parents($term->tid);
+ if (($vocabulary_tokens = token_find_with_prefix($tokens, 'parent')) && $parents = taxonomy_get_parents($term->tid)) {
$parent = array_pop($parents);
$replacements += token_generate('term', $vocabulary_tokens, array('term' => $parent), $options);
}