function taxonomy_breadcrumb_taxonomy in Taxonomy Breadcrumb 6
Same name and namespace in other branches
- 5 taxonomy_breadcrumb.module \taxonomy_breadcrumb_taxonomy()
- 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 186 - 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 ($type == 'vocabulary' || $type == 'term') {
// Include the .inc file with all helper functions.
include_once drupal_get_path('module', 'taxonomy_breadcrumb') . '/taxonomy_breadcrumb.inc';
// 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 = isset($object[$key_type]) ? $object[$key_type] : NULL;
switch ($op) {
case 'insert':
case 'update':
// If (after a vocabulary or term is updated)
// called by module_invoke_all('taxonomy', 'update', 'term', $edit) in taxonomy.module.
$new_path = isset($object['taxonomy_breadcrumb_path']) ? $object['taxonomy_breadcrumb_path'] : NULL;
// Only modify database when the object has the 'taxonomy_breadcrumb_path' field
if (!is_null($new_path)) {
// Delete the record from taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term.
if (drupal_strlen($new_path) == 0 && $old_path !== NULL) {
db_query("DELETE FROM {$table} WHERE {$key_type} = %d", $key);
}
elseif (drupal_strlen($new_path) != 0 && $old_path != NULL) {
db_query("UPDATE {$table} SET path = '%s' WHERE {$key_type} = %d", $new_path, $key);
}
elseif (drupal_strlen($new_path) != 0 && $old_path == NULL) {
db_query("INSERT INTO {$table} ({$key_type}, path) VALUES (%d, '%s')", $key, $new_path);
}
}
break;
case 'delete':
db_query("DELETE FROM {$table} WHERE {$key_type} = %d", $key);
break;
}
}
}