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-05 00:37:40.000000000 +0200
@@ -127,6 +127,29 @@ function category_menu_nodeapi(&$node, $
}
/**
+ * Implementation of hook_menu_link_alter().
+ *
+ * Guards certain properties of existing maintained menu links against
+ * outside changes, so that we explain the flow immediately, rather than
+ * blowing the changes silently later on node edits.
+ */
+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']))) {
+ $changed = FALSE;
+ foreach (array('expanded', 'plid', 'link_title', 'hidden') as $key) {
+ if ($item[$key] != $old_item[$key]) {
+ $item[$key] = $old_item[$key];
+ $changed = TRUE;
+ }
+ }
+ if ($changed) {
+ drupal_set_message(t('Your changes to the %title item may not be saved, because this item is maintained by the category_menu module. You need to !edit-link the node, in order to change this item.', array('%title' => $item['link_title'], '!edit-link' => l(t('edit'), $item['link_path'] .'/edit'))), 'error');
+ }
+ }
+ unset($item['options']['category_menu_unlock']);
+}
+
+/**
* Implementation of hook_form_alter().
*
* Adds the category menu settings to the container node form.
@@ -301,6 +324,14 @@ function category_menu_form_alter(&$form
}
}
}
+
+ // Menu items owned by category_menu module should not be edited from menu admin UI,
+ // as we can't keep the changes anyway. If someone hits the form, redirect to the
+ // corresponding node edit form instead.
+ if ($form_id == 'menu_edit_item' && $form['menu']['#item']['module'] == 'category_menu') {
+ drupal_set_message(t('The menu item %title may not be edited directly, because this item is maintained by the category_menu module. You have been redirected to edit the node instead, as this is where you can make changes to that item.', array('%title' => $form['menu']['#item']['link_title'])));
+ drupal_goto($form['menu']['#item']['link_path'] .'/edit', 'destination='. urlencode('admin/build/menu-customize/'. $form['menu']['#item']['menu_name']));
+ }
}
/**
@@ -585,7 +616,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 +681,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 {
@@ -700,8 +732,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.
diff -urp --strip-trailing-cr ../category/category.module ./category.module
--- ../category/category.module 2009-05-31 12:06:26.000000000 +0200
+++ ./category.module 2009-06-05 00:40:24.000000000 +0200
@@ -1454,10 +1454,15 @@ function _category_add_form_elements(&$f
}
}
+ // When category_menu have an existing menu item, we have two weights here (to be synchronized
+ // later on submit). We want to keep the more recent one, to avoid reversal of user's changes.
+ // The menu weight may be changed outside of this form (via menu reordering on admin UI), while
+ // weight on node only changes later in this form. So, we use menu weight here.
+ $default_weight = empty($node->category_menu_map) ? $node->category['weight'] : $node->category_menu_map['weight'];
$form['category']['hierarchy']['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
- '#default_value' => $node->category['weight'],
+ '#default_value' => $default_weight,
'#delta' => 15,
'#weight' => 10,
'#description' => t('Categories and containers at a given level are ordered first by weight and then by title.'),