diff -urp --strip-trailing-cr ../category/category_menu/category_menu.install ./category_menu/category_menu.install
--- ../category/category_menu/category_menu.install 2009-02-07 10:01:16.000000000 +0100
+++ ./category_menu/category_menu.install 2009-06-08 18:59:18.000000000 +0200
@@ -16,10 +16,26 @@ function category_menu_install() {
}
/**
+ * Implementation of hook_disable().
+ */
+function category_menu_disable() {
+ drupal_set_message(t('The category_menu module is now disabled. This means that generated menu items are no longer maintained. In order to avoid future problems with outdated menu items, it\'s highly recommended to either enable category_menu, or uninstall it entirely (removes all generated menu items).', array('!url' => url('admin/build/modules/uninstall'))), 'warning');
+}
+
+/**
* Implementation of hook_uninstall().
*/
function category_menu_uninstall() {
drupal_uninstall_schema('category_menu');
+
+ $types = node_get_types('names');
+ foreach ($types as $type => $name) {
+ variable_del('category_menu_links_'. $type);
+ }
+ // Remove all generated menu links, as these are no longer maintained,
+ // and user can't delete them (only just disable).
+ db_query("DELETE FROM {menu_links} WHERE module = 'category_menu'");
+ menu_rebuild();
}
function category_menu_schema() {
diff -urp --strip-trailing-cr ../category/category_menu/category_menu.module ./category_menu/category_menu.module
--- ../category/category_menu/category_menu.module 2009-05-31 12:24:23.000000000 +0200
+++ ./category_menu/category_menu.module 2009-06-08 20:20:29.000000000 +0200
@@ -108,6 +108,20 @@ function category_menu_nodeapi(&$node, $
_category_menu_flatten_values($node);
if (!empty($behavior) && $behavior == 'container') {
+ // On updates of already populated containers, show a reminder to refresh
+ // site's data through category_resave, if critical menu settings changed.
+ if ($op == 'update' && db_fetch_array(db_query("SELECT * FROM {category} WHERE cnid = %d", $node->nid))) {
+ $old_settings = (array) category_menu_get_container($node->nid);
+ if (!empty($node->category_menu['links_for_nodes'])) {
+ $node->category_menu['links_for_nodes'] = array_filter($node->category_menu['links_for_nodes']);
+ }
+ foreach (array('links_for_cats', 'expanded_for_cats', 'menu_name', 'links_for_nodes') as $key) {
+ if (isset($old_settings[$key]) && $old_settings[$key] != $node->category_menu[$key]) {
+ drupal_set_message(t('Your changes affected behavior of generated menu links. To apply these changes properly, you need to refresh categories and/or nodes in this container now. The category resave module offers an easy way to perform this operation on existing content.'));
+ break;
+ }
+ }
+ }
category_menu_save_container($node);
}
@@ -127,9 +141,38 @@ function category_menu_nodeapi(&$node, $
}
/**
+ * Implementation of hook_menu_link_alter().
+ *
+ * Deals with external changes to maintained menu links before they are saved,
+ * either by merging the changes back into category system, or disallowing
+ * the changes to be saved.
+ */
+function category_menu_menu_link_alter(&$item, $menu) {
+ if ($item['module'] == 'category_menu' && empty($item['options']['category_menu_unlock']) && !empty($item['mlid']) && $old_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $item['mlid']))) {
+ // Disallow changes to these values, because we cannot keep them: Next
+ // edit of the node is going to overwrite them.
+ foreach (array('expanded', 'plid', 'link_title', 'hidden') as $key) {
+ if ($item[$key] != $old_item[$key]) {
+ $item[$key] = $old_item[$key];
+ }
+ }
+ // Merge new menu item weight back to category, so that reordering of menus work.
+ // This is split into two queries, to avoid PgSQL compatibility issues on JOINs.
+ if ($item['weight'] != $old_item['weight']) {
+ $node = db_fetch_array(db_query("SELECT * FROM {category_menu_map} WHERE mlid = %d", $item['mlid']));
+ if (!empty($node['nid'])) {
+ db_query("UPDATE {category} SET weight = %d WHERE cid = %d", $item['weight'], $node['nid']);
+ }
+ }
+ }
+ unset($item['options']['category_menu_unlock']);
+}
+
+/**
* Implementation of hook_form_alter().
*
- * Adds the category menu settings to the container node form.
+ * Adds the category menu settings to the container node form,
+ * and alters menu overview screen for compatibility.
*/
function category_menu_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value']
@@ -301,6 +344,19 @@ function category_menu_form_alter(&$form
}
}
}
+
+ // Grey-out incompatible settings for maintained menu items on the menu overview
+ // screen, and swap edit link to point to corresponding node edit.
+ if ($form_id == 'menu_overview_form') {
+ $title = t('To change this item, you need to edit the corresponding node.');
+ foreach ($form as $key => $row) {
+ if (!empty($row['#item']['module']) && $row['#item']['module'] == 'category_menu') {
+ $form[$key]['hidden']['#disabled'] = TRUE;
+ $form[$key]['expanded']['#disabled'] = TRUE;
+ $form[$key]['operations']['edit']['#value'] = l(t('edit node'), $row['#item']['link_path'] .'/edit', array('query' => drupal_get_destination(), 'attributes' => array('title' => $title)));
+ }
+ }
+ }
}
/**
@@ -585,7 +641,7 @@ function category_menu_map_load($mlid) {
* during hook_nodeapi('load').
*/
function category_menu_map_load_by_nid($nid) {
- if ($item = db_fetch_array(db_query('SELECT ml.*, cmm.nid, m.* FROM {menu_links} ml INNER JOIN {category_menu_map} cmm ON cmm.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE cmm.nid = %d', $nid))) {
+ if ($item = db_fetch_array(db_query('SELECT m.*, cmm.nid, ml.* FROM {menu_links} ml INNER JOIN {category_menu_map} cmm ON cmm.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE cmm.nid = %d', $nid))) {
$item['options'] = unserialize($item['options']);
return $item;
@@ -650,6 +706,7 @@ function category_menu_map_save($node) {
}
$node->category_menu_map['expanded'] = $container_settings['expanded_for_cats'];
+ $node->category_menu_map['weight'] = $node->category['weight'];
}
// Logic for assigned node types.
else {
@@ -692,6 +749,8 @@ function category_menu_map_save($node) {
}
$new_plid = $assigned_cat_menu_link['mlid'];
+ // Weight for nodes will be re-saved as is (if available), to keep possible
+ // menu order customizations.
}
$node->category_menu_map['menu_name'] = category_menu_menu_name($container_settings['menu_name'], $container_settings['cid']);
@@ -700,8 +759,10 @@ function category_menu_map_save($node) {
$node->category_menu_map['parent_mismatch'] = FALSE;
$node->category_menu_map['module'] = 'category_menu';
$node->category_menu_map['plid'] = $new_plid;
+ $node->category_menu_map['hidden'] = (int) !$node->status;
$menu_name = $node->category_menu_map['menu_name'];
+ $node->category_menu_map['options']['category_menu_unlock'] = TRUE;
if (menu_link_save($node->category_menu_map)) {
if ($new) {
// Insert new.