From 22e8bb504dee5c70a2454ab55b4d4c35e677f59a Fri, 5 Aug 2011 09:55:16 +0200
From: Bram Goffings <bramgoffings@gmail.com>
Date: Fri, 5 Aug 2011 09:55:09 +0200
Subject: [PATCH] content type checkboxes in menu edit menu



diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc
index cb33cbb..3271756 100644
--- a/modules/menu/menu.admin.inc
+++ b/modules/menu/menu.admin.inc
@@ -465,6 +465,23 @@
     '#title' => t('Description'),
     '#default_value' => $menu['description'],
   );
+
+  $content_types = array();
+  foreach (node_type_get_names() as $content_type => $name) {
+    $menu_options = variable_get('menu_options_' . $content_type, array('main-menu'));
+    if(in_array($menu['menu_name'], $menu_options)) {
+      $content_types[] = $content_type;
+    }
+  }
+  $form['menu_content_types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Available content types'),
+    '#default_value' => $content_types,
+    '#description' => t('The content types available that can use this menu.'),
+    '#options' => node_type_get_names(),
+    '#access' => $type == 'edit'
+  );
+
   $form['actions'] = array('#type' => 'actions');
   $form['actions']['submit'] = array(
     '#type' => 'submit',
@@ -593,6 +610,20 @@
       $link['link_title'] = $menu['title'];
       menu_link_save($link);
     }
+
+    $content_types = $menu['menu_content_types'];
+    foreach ($content_types as $content_type => $value) {
+      $menu_options = variable_get('menu_options_' . $content_type, array('main-menu'));
+      if (empty($value) && in_array($menu['menu_name'], $menu_options)) {
+        // Remove this menu from the content type.
+        $menu_options = array_diff($menu_options, array($menu['menu_name']));
+      }
+      elseif (!empty($value) && !in_array($menu['menu_name'], $menu_options)) {
+        // Add this menu to the content type.
+        $menu_options[] = $menu['menu_name'];
+      }
+      variable_set('menu_options_' . $content_type, $menu_options);
+    }
   }
   drupal_set_message(t('Your configuration has been saved.'));
   $form_state['redirect'] = $path . $menu['menu_name'];
