From bfff155b4bf17a3e6b7407cc03c98260eb674050 Mon Sep 17 00:00:00 2001
From: nielsonm <michael@opensourcery.com>
Date: Fri, 24 May 2013 14:36:55 -0700
Subject: [PATCH] Rebasing type-table-1938918-2.patch to HEAD, completed
 converting menu tables to table element form type.

---
 core/modules/menu/menu.admin.inc |   63 +++++++++++++++++++++++++++++++++++---
 core/modules/menu/menu.module    |   12 --------
 2 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc
index 4150b99..fe34f43 100644
--- a/core/modules/menu/menu.admin.inc
+++ b/core/modules/menu/menu.admin.inc
@@ -67,8 +67,6 @@ function menu_overview_form($form, &$form_state) {
 
   // Ensure that menu_overview_form_submit() knows the parents of this form
   // section.
-  $form['#tree'] = TRUE;
-  $form['#theme'] = 'menu_overview_form';
   $form_state += array('menu_overview_form_parents' => array());
 
   $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.admin.css');
@@ -108,8 +106,65 @@ function menu_overview_form($form, &$form_state) {
       'title' => t('Add link'),
     ),
   );
-  $form = array_merge($form, _menu_overview_tree_form($tree, $delta));
-  $form['#empty_text'] = t('There are no menu links yet. <a href="@link">Add link</a>.', array('@link' => url('admin/structure/menu/manage/' . $form_state['menu']->id() .'/add')));
+
+  $form['links'] = array(
+    '#type' => 'table',
+    '#attributes' => array('id' => 'menu-overview'),
+    '#header' => array(
+      t('Menu link'),
+      array('data' => t('Enabled'), 'class' => array('checkbox')),
+      t('Weight'),
+      t('Operations'),
+    ),
+    '#empty' => t('There are no menu links yet. <a href="@link">Add link</a>.', array('@link' => url('admin/structure/menu/manage/' . $form_state['menu']->id() .'/add'))),
+    '#tabledrag' => array(
+      array('match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1),
+      array('order', 'sibling', 'menu-weight'),
+    ),
+  );
+
+  $links = _menu_overview_tree_form($tree, $delta);
+  foreach (element_children($links) as $mlid) {
+    $element = $links[$mlid];
+
+    // Add special classes to be used for tabledrag.js.
+    $element['plid']['#attributes']['class'] = array('menu-plid');
+    $element['mlid']['#attributes']['class'] = array('menu-mlid');
+    $element['weight']['#attributes']['class'] = array('menu-weight');
+
+    $form['links'][$mlid]['#attributes']['class'][] = 'draggable';
+    $form['links'][$mlid]['#weight'] =  $element['#item']->get('weight');
+
+    $form['links'][$mlid]['title'] = array(
+      array(
+        '#theme' => 'indentation',
+        '#size' => ($element['#item']->depth - 1),
+      ),
+      $element['title'],
+    );
+
+    $form['links'][$mlid]['hidden'] = array(
+      'data' => $element['hidden'],
+      '#attributes' => array('class' => array('checkbox', 'menu-enabled')),
+    );
+
+    // Set the parents for each of the elements so that
+    // form elements share the parent's form attributes.
+    $form['links'][$mlid]['weight'] = array(
+      'weight' => $element['weight'] + array(
+        '#parents' => array('links', $mlid, 'weight')
+      ),
+      'plid' => $element['plid'] + array(
+        '#parents' => array('links', $mlid, 'plid')
+      ),
+      'mlid' => $element['mlid'] + array(
+        '#parents' => array('links', $mlid, 'mlid')
+      ),
+    );
+
+    // Operations (dropbutton) column.
+    $form['links'][$mlid]['operations'] = $element['operations'];
+  }
 
   return $form;
 }
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index 1b43a4e..b7a0e17 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -165,18 +165,6 @@ function menu_uri(Menu $menu) {
 }
 
 /**
- * Implements hook_theme().
- */
-function menu_theme() {
-  return array(
-    'menu_overview_form' => array(
-      'file' => 'menu.admin.inc',
-      'render element' => 'form',
-    ),
-  );
-}
-
-/**
  * Implements hook_enable().
  *
  * Add a link for each custom menu.
-- 
1.7.10.4

