From 3aab4d163b182bf6a23a65346dcfbaa9860d76e8 Fri, 5 Aug 2011 00:39:50 +0200
From: Bram Goffings <bramgoffings@gmail.com>
Date: Fri, 5 Aug 2011 00:39:40 +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..75521b3 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('Content type'),
+    '#default_value' => $content_types,
+    '#description' => t('some description'),
+    '#options' => node_type_get_names(),
+    '#access' => $type == 'edit'
+  );
+
   $form['actions'] = array('#type' => 'actions');
   $form['actions']['submit'] = array(
     '#type' => 'submit',
@@ -593,6 +610,21 @@
       $link['link_title'] = $menu['title'];
       menu_link_save($link);
     }
+
+    $content_types = $menu['menu_content_types'];
+    foreach (node_type_get_names() as $content_type => $name) {
+      $menu_options = variable_get('menu_options_' . $content_type, array('main-menu'));
+      if (empty($content_types[$content_type]) && 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($content_types[$content_type]) && !in_array($menu['menu_name'], $menu_options)) {
+        // add this menu to the content type
+        $menu_options[] = $menu['menu_name'];
+      }
+      // save the new menu options
+      variable_set('menu_options_' . $content_type, $menu_options);
+    }
   }
   drupal_set_message(t('Your configuration has been saved.'));
   $form_state['redirect'] = $path . $menu['menu_name'];
