Jump to:
| Project: | Taxonomy menu |
| Version: | master |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
With a discussion with pwolanin, a contributor to the new Drupal menu system in v6, he gave very strong warnings about using the router table to generate links. For example "categories/234/34/344/33/4" type item as a callback for the view/term page. Namely speed and memory issues
Rather he say it was best to generate the single callback "categories/%" and then using taxonomy_hook or a custom callback to generate the menu items using menu_link_save. I am using the module in a very modified form, the refactoring that I have used, is similar to this: (Not runnable, I simply cut out the extra bits of code during the post)
<?php
// create single callback and using wildcard loader to preload the vocab
$path = variable_get('taxonomy_menu_display_page', 'category');
$arg_pos = count(explode('/', $path));
$items[$path . '/%taxonomy_vocabulary'] = array(
'title' => t($path),
'page callback' => '_taxonomy_menu_general_menu_page',
'page arguments' => array($arg_pos),
'access arguments' => array('access content'),
'file' => 'taxonomy_menu.page.inc',
);
?>and generating the links using:
<?php
/**
* Mine is modified to be vocab specific. I've cut out most of this
*/
function taxonomy_menu_create_menu_links() {
// delete the old menu items for this $vocab
$path = variable_get('taxonomy_menu_display_page', 'category');
db_query("DELETE FROM {menu_links} WHERE module = 'taxonomy_menu'");
// as per the normal module, but generate menu item rather than router link
$tree = taxonomy_get_tree($vocab->vid);
$old_depth = -1;
$old_path = $path;
foreach ($tree as $index => $term) {
if ($term->depth <= $old_depth) {
$slashes_to_remove = $old_depth - $term->depth + 1;
for ($i = 0; $i < $slashes_to_remove; $i++) {
$old_path = substr($old_path, 0, strrpos($old_path, '/'));
}
}
$path = $old_path .'/'. $term->tid;
$old_depth = $term->depth;
$old_path = $path;
$num = taxonomy_term_count_nodes($term->tid);
if (variable_get('taxonomy_menu_hide_empty', FALSE) == FALSE or $num != 0) {
$name = t($term->name);
if (variable_get('taxonomy_menu_display_num', FALSE) == TRUE) {
$name .= ' ('. $num .')';
}
$item = array(
'link_title' => $name,
'link_path' => $path,
'router_path' => $router_path,
'weight' => $term->weight,
'menu_name' => 'navigation',
'module' => 'taxonomy_menu', // used as a hook for delete, the ones in the hook_menu as linked to system
);
menu_link_save($item);
}
}
}
?>If you run "menu_link_save" during rebuild menus / flush cache, the install will crash due to recursion. That was fun debugging :) Thus the second function needs to be decoupled from the hook_menu. My hacked version simply appends it with a shut-down function. taxonomy_hook and maybe an admin link to regenerate menu items would be the best place.
Hope this helps / makes sense.
Comments
#1
I think this was taken to heart in the latest builds....
#2
Automatically closed -- issue fixed for 2 weeks with no activity.