menu_editor.admin.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. /**
  3. * Form for editing an entire menu tree at once.
  4. *
  5. * Shows for one menu the menu items accessible to the current user and
  6. * relevant operations.
  7. */
  8. function menu_editor_overview_form($form, &$form_state, $menu) {
  9. global $menu_admin;
  10. $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.css');
  11. $sql = "
  12. SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
  13. FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
  14. WHERE ml.menu_name = :menu
  15. ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
  16. $result = db_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
  17. $links = array();
  18. foreach ($result as $item) {
  19. $links[] = $item;
  20. }
  21. $tree = menu_tree_data($links);
  22. $node_links = array();
  23. menu_tree_collect_node_links($tree, $node_links);
  24. // We indicate that a menu administrator is running the menu access check.
  25. $menu_admin = TRUE;
  26. menu_tree_check_access($tree, $node_links);
  27. $menu_admin = FALSE;
  28. $form = array('#tree' => TRUE);
  29. $form['#multilingual_menu'] = FALSE;
  30. $form['#translatable_nodes'] = FALSE;
  31. $max_root_weight = _menu_editor_overview_tree_form($form, $form_state, $tree);
  32. // default values for all new menu items..
  33. $default_values = array(
  34. 'link_title' => '',
  35. 'link_path' => '<front>',
  36. 'description' => '',
  37. 'hidden' => true,
  38. 'expanded' => false,
  39. 'weight' => 0,
  40. // 'mlid' => NULL, // this is different for every single one
  41. 'plid' => 0,
  42. 'language' => LANGUAGE_NONE,
  43. );
  44. foreach (menu_editor_get_placeholders() as $placeholder_code => $placeholder_path) {
  45. // take the first placeholder as default link path instead of <front>
  46. $default_values['link_path'] = $placeholder_code;
  47. break;
  48. }
  49. for ($i=0; $i<8; ++$i) {
  50. // new menu item
  51. $default_values['mlid'] = 'new' . $i;
  52. $item_key = 'mlid-new'.$i;
  53. $form[$item_key] = _menu_editor_overview_tree_form_item('new'.$i, $default_values, $form['#multilingual_menu']);
  54. $form[$item_key]['weight']['#default_value'] = $max_root_weight + $i + 1;
  55. $form[$item_key]['#item'] = array();
  56. $form[$item_key]['#attributes'] = array('class' => 'menu-new');
  57. $form[$item_key]['drag']['#markup'] = t('New menu item');
  58. }
  59. $form['#menu'] = $menu;
  60. if (element_children($form)) {
  61. $form['submit'] = array(
  62. '#type' => 'submit',
  63. '#value' => t('Save configuration'),
  64. );
  65. }
  66. else {
  67. $form['empty_menu'] = array('#value' => t('There are no menu items yet.'));
  68. }
  69. return $form;
  70. }
  71. /**
  72. * Recursive helper function for menu_overview_form().
  73. */
  74. function _menu_editor_overview_tree_form(&$form, &$form_state, $tree) {
  75. $max_root_weight = 0;
  76. foreach ($tree as $data) {
  77. $title = '';
  78. $item = $data['link'];
  79. // Don't show callbacks; these have $item['hidden'] < 0.
  80. if ($item && $item['hidden'] >= 0) {
  81. $item_key = 'mlid-'. $item['mlid'];
  82. $weight = isset($form_state[$item_key]['weight']) ? $form_state[$item_key]['weight'] : $item['weight'];
  83. $plid = isset($form_state[$item_key]['plid']) ? $form_state[$item_key]['plid'] : $item['plid'];
  84. if (!$plid && $weight > $max_root_weight) {
  85. // this is a root level item
  86. $max_root_weight = $weight;
  87. }
  88. $path = $item['link_path'];
  89. if (!empty($item['options']['query'])) {
  90. if (is_array($item['options']['query'])) {
  91. $path .= '?'. drupal_http_build_query($item['options']['query']);
  92. }
  93. else {
  94. // Query could be a string, due to a malfunction in previous versions of this module.
  95. $path .= '?'. $item['options']['query'];
  96. }
  97. }
  98. if (isset($item['options']['fragment'])) {
  99. $path .= '#'. $item['options']['fragment'];
  100. }
  101. $default_values = array(
  102. 'link_title' => $item['link_title'],
  103. 'link_path' => $path,
  104. 'description' => isset($item['options']['attributes']['title']) ? $item['options']['attributes']['title'] : '',
  105. 'hidden' => !$item['hidden'],
  106. 'expanded' => $item['expanded'],
  107. 'weight' => $weight,
  108. 'plid' => $plid,
  109. 'depth' => 1,
  110. );
  111. $form[$item_key] = _menu_editor_overview_tree_form_item($item['mlid'], $default_values, $form['#multilingual_menu']);
  112. $form[$item_key]['#item'] = $item;
  113. $form[$item_key]['#attributes'] = $item['hidden'] ? array('class' => 'menu-disabled') : array('class' => 'menu-enabled');
  114. $form[$item_key]['drag']['#markup'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' ('. t('disabled') .')' : '');
  115. // Include i18n support.
  116. if (module_exists('i18n_menu')) {
  117. $item['language'] = i18n_menu_item_get_language($item);
  118. $node_item = ($node = i18n_menu_item_get_node($item)) && i18n_menu_node_supported_type($node->type);
  119. if (!$node_item && i18n_menu_mode($item['menu_name'], I18N_MODE_TRANSLATE)) {
  120. $form[$item_key]['language'] = array('#title' => NULL) + i18n_element_language_select($item);
  121. $form['#multilingual_menu'] = TRUE;
  122. // If the term to be added will be a translation of a source term,
  123. // set the default value of the option list to the target language and
  124. // create a form element for storing the translation set of the source term.
  125. if (isset($_GET['translation']) && isset($_GET['target']) && ($source_item = menu_link_load($_GET['translation']))) {
  126. if (!empty($source_item['i18n_tsid'])) {
  127. $translation_set = i18n_translation_set_load($source_item['i18n_tsid']);
  128. }
  129. else {
  130. // Create object and stick the source information in the translation set.
  131. $translation_set = i18n_translation_set_build('menu_link')
  132. ->add_item($source_item);
  133. }
  134. $form[$item_key]['link_path']['#default_value'] = $source_item['link_path'];
  135. // Maybe we should disable the 'link_path' and 'parent' form elements?
  136. // $form['link_path']['#disabled'] = TRUE;
  137. // $form['parent']['#disabled'] = TRUE;
  138. $form[$item_key]['language']['#default_value'] = $_GET['target'];
  139. $form[$item_key]['language']['#disabled'] = TRUE;
  140. }
  141. }
  142. else {
  143. $form[$item_key]['language'] = array(
  144. '#type' => 'value',
  145. '#value' => $item['language'],
  146. );
  147. }
  148. // Aside from the usual conditions from i18n_menu_form_menu_edit_item_alter(), also
  149. // check if the return of the language name isn't "Undefined". This is caused when
  150. // choosing "Translate mode" to be "No multilingual options for menu items. Only the
  151. // menu will be translatable." but one of the menu items is a node which
  152. // is translatable.
  153. if ($node_item && i18n_langcode($item['language'])) {
  154. $form[$item_key]['lang_message'] = array(
  155. '#type' => 'markup',
  156. '#title' => t('Language'),
  157. '#markup' => i18n_language_name($item['language']),
  158. );
  159. $form['#translatable_nodes'] = TRUE;
  160. }
  161. }
  162. // Only items created by the menu module can be deleted.
  163. if ($item['module'] == 'menu' || $item['updated'] == 1) {
  164. $form[$item_key]['delete'] = array(
  165. '#type' => 'checkbox',
  166. '#title' => t('delete'),
  167. '#default_value' => false,
  168. );
  169. }
  170. }
  171. // process child elements
  172. if ($data['below']) {
  173. _menu_editor_overview_tree_form($form, $form_data, $data['below']);
  174. }
  175. }
  176. return $max_root_weight;
  177. }
  178. function _menu_editor_overview_tree_form_item($item_mlid, $default_values, $multilingual_menu = FALSE) {
  179. foreach (menu_editor_get_placeholders() as $code => $path) {
  180. if (str_replace('@mlid', $item_mlid, $path) == $default_values['link_path']) {
  181. $default_values['link_path'] = $code;
  182. }
  183. }
  184. $element = array();
  185. $element['link_title'] = array(
  186. '#type' => 'textfield',
  187. '#size' => 25,
  188. );
  189. $element['link_path'] = array(
  190. '#type' => 'textfield',
  191. '#size' => 25,
  192. );
  193. $element['description'] = array(
  194. '#type' => 'textarea',
  195. '#cols' => 8,
  196. '#rows' => 1,
  197. '#resizable' => FALSE,
  198. );
  199. $element['hidden'] = array(
  200. '#type' => 'checkbox',
  201. );
  202. $element['expanded'] = array(
  203. '#type' => 'checkbox',
  204. );
  205. $element['weight'] = array(
  206. // The original form uses a select box for the weight.
  207. // We use a textfield instead, to save memory on server side
  208. // and to reduce page size.
  209. '#type' => 'textfield',
  210. '#size' => 4,
  211. '#element_validate' => array('_menu_editor_valid_weight'),
  212. );
  213. $element['mlid'] = array(
  214. '#type' => 'hidden',
  215. '#value' => $item_mlid,
  216. );
  217. $element['plid'] = array(
  218. '#type' => 'textfield',
  219. '#size' => 6,
  220. );
  221. // If this is a new menu item, simply provide i18n_menu select options.
  222. if (strpos($item_mlid, 'new') === 0 && $multilingual_menu) {
  223. $element['language'] = array('#title' => NULL) + i18n_element_language_select();
  224. }
  225. foreach ($default_values as $key => $value) {
  226. if (isset($element[$key])) {
  227. $element[$key]['#default_value'] = $value;
  228. }
  229. }
  230. return $element;
  231. }
  232. /**
  233. * Weight textfield validation function
  234. * Stolen from http://drupal.org/project/tiny_menu_editor
  235. * Big thanks to Dmitriy.trt
  236. */
  237. function _menu_editor_valid_weight($element, &$form_state) {
  238. if ((isset($element['#value']) && $element['#value'] !== '') || !empty($element['#required'])) {
  239. if (!preg_match('/^\-?\d+$/', $element['#value'])) {
  240. form_error($element, t('Weight has to be an integer value.'));
  241. }
  242. }
  243. }
  244. function menu_editor_overview_form_validate($form, &$form_state) {
  245. $form_values = &$form_state['values'];
  246. // Check existing items.
  247. foreach (element_children($form) as $item_key) {
  248. // Check if these are menu items.
  249. if (strpos($item_key, 'mlid-') !== FALSE) {
  250. $element = &$form[$item_key];
  251. if (isset($element['link_path'])) {
  252. menu_editor_validate_item($element, $element['link_path']['#value'], $item_key . '][');
  253. }
  254. }
  255. }
  256. // allow new items to be dynamically added via javascript,
  257. // that have not been in the form originally.
  258. foreach ($form_state['input'] as $item_key => $item) {
  259. if (preg_match('/^mlid-new\d+$/', $item_key)) {
  260. if (menu_editor_overview_form_validate_new_item($item)) {
  261. $form_values[$item_key] = $item;
  262. }
  263. }
  264. }
  265. }
  266. /**
  267. * Validate form values for a menu link being added or edited.
  268. */
  269. function menu_editor_validate_item(&$element, $link_path, $error_key_prefix) {
  270. $placeholders = menu_editor_get_placeholders();
  271. if (isset($placeholders[$link_path])) {
  272. // it would be hard to check access,
  273. // because we don't necessarily know the mlid.
  274. // Thus, we simply grant access for all placeholders.
  275. return;
  276. }
  277. if ($element['link_path']['#default_value'] == $link_path) {
  278. // link_path is the only field that we check,
  279. // and we don't complain about existing link paths.
  280. return;
  281. }
  282. $item = $element['#item'];
  283. $normal_path = drupal_get_normal_path($link_path);
  284. $item['link_path'] = $normal_path;
  285. if (!url_is_external($normal_path)) {
  286. $parsed_link = parse_url($normal_path);
  287. if (isset($parsed_link['query'])) {
  288. $item['options']['query'] = drupal_get_query_array($parsed_link['query']);
  289. }
  290. if (isset($parsed_link['fragment'])) {
  291. $item['options']['fragment'] = $parsed_link['fragment'];
  292. }
  293. $item['link_path'] = $parsed_link['path'];
  294. }
  295. if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'])) {
  296. form_set_error($error_key_prefix . 'link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
  297. }
  298. }
  299. /**
  300. * validate a menu item that was dynamically added through javascript
  301. *
  302. * @param unknown_type $item
  303. */
  304. function menu_editor_overview_form_validate_new_item($item) {
  305. // TODO: add some sanity checks
  306. return true;
  307. }
  308. /**
  309. * Submit handler for the menu overview form.
  310. *
  311. * This function takes great care in saving parent items first, then items
  312. * underneath them. Saving items in the incorrect order can break the menu tree.
  313. *
  314. * @see menu_overview_form()
  315. */
  316. function menu_editor_overview_form_submit($form, &$form_state) {
  317. // When dealing with saving menu items, the order in which these items are
  318. // saved is critical. If a changed child item is saved before its parent,
  319. // the child item could be saved with an invalid path past its immediate
  320. // parent. To prevent this, save items in the form in the same order they
  321. // are sent by $_POST, ensuring parents are saved first, then their children.
  322. // See http://drupal.org/node/181126#comment-632270
  323. $item_keys = array_flip(array_keys($form_state['input'])); // Get the $_POST order.
  324. $form_values = array_merge($item_keys, $form_state['values']); // Update our original form with the new order.
  325. $menu_name = $form['#menu']['menu_name'];
  326. $updated_items = array();
  327. $fields = array('expanded', 'weight', 'plid', 'link_title', 'link_path', 'description');
  328. foreach ($form_values as $item_key => $v) {
  329. if (isset($form[$item_key]['#item'])) {
  330. $element = $form[$item_key];
  331. if (!is_numeric($v['mlid'])) {
  332. // add new item
  333. unset($v['mlid']);
  334. if (!is_string($v['link_title']) || empty($v['link_title'])) {
  335. continue;
  336. }
  337. if (!is_string($v['link_path']) || empty($v['link_path'])) {
  338. continue;
  339. }
  340. $element['#item']['menu_name'] = $menu_name;
  341. // Set all fields in this menu item.
  342. foreach ($fields as $field) {
  343. // Check if field is set since some fields could not be NULL when
  344. // doing menu_link_save().
  345. if (isset($v[$field])) {
  346. $element['#item'][$field] = $v[$field];
  347. }
  348. }
  349. $updated_items[$item_key] = $element['#item'];
  350. } else if (!empty($v['delete'])) {
  351. // delete existing item
  352. if (is_numeric($v['mlid'])) {
  353. menu_link_delete($v['mlid']);
  354. }
  355. continue;
  356. } else {
  357. // update existing item
  358. // Update any fields that have changed in this menu item.
  359. foreach ($fields as $field) {
  360. if ($v[$field] != $element[$field]['#default_value']) {
  361. $element['#item'][$field] = $v[$field];
  362. $updated_items[$item_key] = $element['#item'];
  363. }
  364. }
  365. }
  366. // Hidden is a special case, the value needs to be inverted.
  367. // Besides, while we operate with boolean, the database wants numeric 0/1.
  368. if ($v['hidden'] xor $element['hidden']['#default_value']) {
  369. $element['#item']['hidden'] = empty($v['hidden']) ? 1 : 0;
  370. $updated_items[$item_key] = $element['#item'];
  371. }
  372. // langcode is a special case as well
  373. if (!empty($form['#multilingual_menu'])) {
  374. $langcode = isset($element['language']['#default_value']) ? $element['language']['#default_value'] : $element['language']['#value'];
  375. if ($v['language'] != $langcode) {
  376. $element['#item']['language'] = $v['language'];
  377. $updated_items[$item_key] = $element['#item'];
  378. }
  379. }
  380. // description is a special case
  381. if (isset($updated_items[$item_key]['description'])) {
  382. $updated_items[$item_key]['options']['attributes']['title'] = $updated_items[$item_key]['description'];
  383. }
  384. }
  385. }
  386. // placeholders to change the link path
  387. $placeholders = menu_editor_get_placeholders();
  388. // Save all our changed items to the database.
  389. $errors = array();
  390. $mlids = array();
  391. foreach ($updated_items as $item_key => $item) {
  392. $item['customized'] = 1;
  393. // check the link path
  394. $link_path = &$item['link_path'];
  395. $link_path_placeholder = NULL;
  396. // placeholders
  397. if (isset($placeholders[$link_path])) {
  398. if (isset($item['mlid']) && is_numeric($item['mlid'])) {
  399. $link_path = str_replace('@mlid', $item['mlid'], $placeholders[$link_path]);
  400. }
  401. else {
  402. $link_path_placeholder = $placeholders[$link_path];
  403. // use a dummy link path,
  404. // until we know the correct mlid.
  405. $link_path = '<front>';
  406. }
  407. }
  408. // clean the link path
  409. if (isset($link_path)) {
  410. $link_path = drupal_get_normal_path($link_path);
  411. if (!url_is_external($link_path)) {
  412. $parsed_link = parse_url($link_path);
  413. if (isset($parsed_link['query'])) {
  414. $item['options']['query'] = drupal_get_query_array($parsed_link['query']);
  415. }
  416. else {
  417. unset($item['options']['query']);
  418. }
  419. if (isset($parsed_link['fragment'])) {
  420. $item['options']['fragment'] = $parsed_link['fragment'];
  421. }
  422. else {
  423. unset($item['options']['fragment']);
  424. }
  425. if ($link_path != $parsed_link['path']) {
  426. $link_path = $parsed_link['path'];
  427. }
  428. }
  429. if (!trim($link_path) || !drupal_valid_path($link_path)) {
  430. // invalid link path, discard this item
  431. continue;
  432. }
  433. }
  434. // drupal_set_message('<pre>' . print_r($item, true) . '</pre>');
  435. if (!empty($item['plid']) && !is_numeric($item['plid'])) {
  436. if (isset($mlids["mlid-$item[plid]"])) {
  437. $item['plid'] = $mlids["mlid-$item[plid]"];
  438. }
  439. else {
  440. unset($item['plid']);
  441. }
  442. }
  443. $mlid = menu_link_save($item);
  444. if (is_numeric($mlid)) {
  445. // remember as a plid for child items
  446. $mlids[$item_key] = $mlid;
  447. if (isset($link_path_placeholder)) {
  448. // overwrite the dummy link path
  449. $link_path = str_replace('@mlid', $item['mlid'], $link_path_placeholder);
  450. menu_link_save($item);
  451. }
  452. }
  453. else {
  454. $errors[] = $item_key;
  455. }
  456. }
  457. if (!empty($errors)) {
  458. drupal_set_message(t('There were errors saving the following menu links:<br/>' . implode('<br/>', $errors)), 'error');
  459. }
  460. }
  461. /**
  462. * Theme the menu overview form into a table.
  463. *
  464. * @ingroup themeable
  465. */
  466. function theme_menu_editor_overview_form($variables) {
  467. $form = $variables['form'];
  468. drupal_add_css(drupal_get_path('module', 'menu_editor') .'/menu_editor.css');
  469. drupal_add_js(drupal_get_path('module', 'menu_editor') . '/menu_editor.js');
  470. global $language;
  471. $i18n_menu = $form['#multilingual_menu'] || $form['#translatable_nodes'];
  472. drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
  473. drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
  474. $header = array();
  475. $header[] = t('Menu item');
  476. $header[] = t('Title');
  477. $header[] = t('Path');
  478. $header[] = array('data' => t('Descr.', array(), array('context' => 'Abbr: "Description"')), 'class' => 'description');
  479. $header[] = array('data' => t('En.', array(), array('context' => 'Abbr: "Enabled"')), 'class' => 'checkbox');
  480. $header[] = array('data' => t('Exp.', array(), array('context' => 'Abbr: "Expanded"')), 'class' => 'checkbox');
  481. $header[] = t('Weight');
  482. if ($i18n_menu) {
  483. $header[] = t('Language');
  484. }
  485. $header[] = array('data' => t('Delete'), 'class' => 'delete-checkbox');
  486. $rows = array();
  487. $items = array();
  488. foreach (element_children($form) as $item_key) {
  489. if (isset($form[$item_key]['hidden'])) {
  490. $element = &$form[$item_key];
  491. // Add special classes to be used for tabledrag.js.
  492. $element['plid']['#attributes']['class'] = array('menu-plid');
  493. $element['mlid']['#attributes']['class'] = array('menu-mlid');
  494. $element['weight']['#attributes']['class'] = array('menu-weight');
  495. // Change the parent field to a hidden. This allows any value but hides the field.
  496. $element['plid']['#type'] = 'hidden';
  497. // Adjust tab index to allow vertical tabbing
  498. foreach (array('link_title', 'link_path', 'description', 'hidden', 'expanded') as $i => $key) {
  499. $element[$key]['#attributes']['tabindex'] = $i+2;
  500. }
  501. $element['link_path']['#attributes']['tabindex'] = 2;
  502. $cells = array();
  503. $size = isset($element['#item']['depth']) ? $element['#item']['depth'] : 1;
  504. $cells['drag'] = array(
  505. 'data' => theme('indentation', array('size' => $size - 1)) . drupal_render($element['drag']),
  506. 'class' => 'drag',
  507. );
  508. $cells['link_title'] = array('data' => drupal_render($element['link_title']), 'class' => 'title-edit');
  509. $cells['link_path'] = array('data' => drupal_render($element['link_path']), 'class' => 'path-edit');
  510. $cells['description'] = array('data' => drupal_render($element['description']), 'class' => 'description');
  511. $cells['hidden'] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox');
  512. $cells['expanded'] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox');
  513. $cells['mlid'] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
  514. if ($i18n_menu) {
  515. if (isset($element['lang_message'])) {
  516. $cells['language'] = array('data' => drupal_render($element['lang_message']));
  517. }
  518. else {
  519. $cells['language'] = array('data' => drupal_render($element['language']), 'class' => 'select');
  520. }
  521. }
  522. $cells['delete'] = array('data' => drupal_render($element['delete']), 'class' => 'delete-checkbox');
  523. $row = array_merge(array('data' => $cells), $element['#attributes']);
  524. $row['class'] = array('draggable');
  525. if ($i18n_menu) {
  526. $langcode = isset($element['language']['#default_value']) ? $element['language']['#default_value'] : $element['language']['#value'];
  527. $row['class'][] = ($langcode != LANGUAGE_NONE) ? 'langcode-'.$langcode : 'all-languages';
  528. $row['class'][]= ($langcode == $language->language) ? 'active-language' : '';
  529. }
  530. $rows[$item_key] = $row;
  531. }
  532. }
  533. $output = '';
  534. // allow other modules to change the table data.
  535. drupal_alter('menu_editor_overview_table', $header, $rows);
  536. $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'menu-overview')));
  537. $output .= drupal_render_children($form);
  538. return $output;
  539. }