You are here

function taxonomy_breadcrumb_taxonomy in Taxonomy Breadcrumb 5

Same name and namespace in other branches
  1. 6 taxonomy_breadcrumb.module \taxonomy_breadcrumb_taxonomy()
  2. 7 taxonomy_breadcrumb.module \taxonomy_breadcrumb_taxonomy()

Implementation of hook_taxonomy(). This implementation checks to see if a vocabulary or term is being updated and makes the necessary changes in the taxonomy_breadcrumb database tables.

File

./taxonomy_breadcrumb.module, line 323
The taxonomy_breadcrumb module generates taxonomy based breadcrumbs on node pages and taxonomy/term pages. The breadcrumb trail takes on the form: [HOME] >> [VOCABULARY] >> TERM >> [TERM] ...

Code

function taxonomy_breadcrumb_taxonomy($op, $type, $object = NULL) {

  // if (after a vocabulary or term is updated)
  // called by module_invoke_all('taxonomy', 'update', 'term', $edit);  in taxonomy.module
  if ($op == 'update' && ($type == 'vocabulary' || $type == 'term')) {

    // Set variables to used in SQL query to reflect if vocabulary or term is
    // being updated.
    if ($type == 'vocabulary') {
      $table = '{taxonomy_breadcrumb_vocabulary}';
      $key_type = 'vid';
      $old_path = taxonomy_breadcrumb_get_vocabulary_path($object['vid']);
    }
    elseif ($type == 'term') {
      $table = '{taxonomy_breadcrumb_term}';
      $key_type = 'tid';
      $old_path = taxonomy_breadcrumb_get_term_path($object['tid']);
    }
    $key = $object[$key_type];
    $new_path = $object['taxonomy_breadcrumb_path'];

    // Delete record from taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term
    if (strlen($new_path) == 0 && $old_path !== NULL) {
      db_query("DELETE FROM {$table} WHERE {$key_type} = %d", $key);
    }
    elseif (strlen($new_path) != 0 && $old_path != NULL) {
      db_query("UPDATE {$table} SET path = '%s' WHERE {$key_type} = %d", $new_path, $key);
    }
    elseif (strlen($new_path) != 0 && $old_path == NULL) {
      db_query("INSERT INTO {$table} ({$key_type}, path) VALUES (%d, '%s')", $key, $new_path);
    }
  }
}