menu_block.admin.inc

Provides infrequently used functions and hooks for menu_block.

Functions

Namesort descending Description
menu_block_add_block_form Menu callback: display the menu block addition form.
menu_block_add_block_form_submit Save the new menu block.
menu_block_admin_settings_form Menu callback: admin settings form.
menu_block_admin_settings_form_submit Form submission handler.
menu_block_configure_form Returns the configuration form for a menu tree.
menu_block_configure_form_follow_validate Validates the follow element of the block configuration form.
menu_block_configure_form_parent_validate Validates the parent element of the block configuration form.
menu_block_delete Menu callback: confirm deletion of menu blocks.
menu_block_delete_submit Deletion of menu blocks.
theme_menu_block_menu_order Theme a drag-to-reorder table of menu selection checkboxes.
_menu_block_block_configure Implements hook_block_configure().
_menu_block_block_info Implements hook_block_info().
_menu_block_block_save Implements hook_block_save().
_menu_block_ctools_plugin_directory Implements hook_ctools_plugin_directory().
_menu_block_format_title Return the title of the block.
_menu_block_form_block_admin_display_form_alter Alters the block admin form to add delete links next to menu blocks.
_menu_block_theme Implements hook_theme().

File

sites/all/modules/local_contrib/menu_block/menu_block.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provides infrequently used functions and hooks for menu_block.
  5. */
  6. /**
  7. * Implements hook_theme().
  8. */
  9. function _menu_block_theme(&$existing, $type, $theme, $path) {
  10. // Add theme hook suggestion patterns for the core theme functions used in
  11. // this module. We can't add them during hook_theme_registry_alter() because
  12. // we will already have missed the opportunity for the theme engine's
  13. // theme_hook() to process the pattern. And we can't run the pattern ourselves
  14. // because we aren't given the type, theme and path in that hook.
  15. $existing['menu_tree']['pattern'] = 'menu_tree__';
  16. $existing['menu_link']['pattern'] = 'menu_link__';
  17. return array(
  18. 'menu_block_wrapper' => array(
  19. 'template' => 'menu-block-wrapper',
  20. 'variables' => array('content' => array(), 'config' => array(), 'delta' => NULL),
  21. 'pattern' => 'menu_block_wrapper__',
  22. ),
  23. 'menu_block_menu_order' => array(
  24. 'render element' => 'element',
  25. 'file' => 'menu_block.admin.inc',
  26. ),
  27. );
  28. }
  29. /**
  30. * Implements hook_ctools_plugin_directory().
  31. */
  32. function _menu_block_ctools_plugin_directory($module, $plugin) {
  33. if ($plugin == 'content_types') {
  34. return 'plugins/' . $plugin;
  35. }
  36. }
  37. /**
  38. * Menu callback: display the menu block addition form.
  39. *
  40. * @see menu_block_add_block_form_submit()
  41. */
  42. function menu_block_add_block_form($form, &$form_state) {
  43. module_load_include('inc', 'block', 'block.admin');
  44. $form = block_admin_configure($form, $form_state, 'menu_block', NULL);
  45. // Other modules should be able to use hook_form_block_add_block_form_alter()
  46. // to modify this form, so add a base form ID.
  47. $form_state['build_info']['base_form_id'] = 'block_add_block_form';
  48. // Prevent block_add_block_form_validate/submit() from being automatically
  49. // added because of the base form ID by providing these handlers manually.
  50. $form['#validate'] = array();
  51. $form['#submit'] = array('menu_block_add_block_form_submit');
  52. return $form;
  53. }
  54. /**
  55. * Save the new menu block.
  56. */
  57. function menu_block_add_block_form_submit($form, &$form_state) {
  58. // Determine the delta of the new block.
  59. $block_ids = variable_get('menu_block_ids', array());
  60. $delta = empty($block_ids) ? 1 : max($block_ids) + 1;
  61. $form_state['values']['delta'] = $delta;
  62. // Save the new array of blocks IDs.
  63. $block_ids[] = $delta;
  64. variable_set('menu_block_ids', $block_ids);
  65. // Save the block configuration.
  66. menu_block_block_save($delta, $form_state['values']);
  67. // Run the normal new block submission (borrowed from block_add_block_form_submit).
  68. $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'region', 'status', 'weight', 'delta', 'cache'));
  69. foreach (list_themes() as $key => $theme) {
  70. if ($theme->status) {
  71. $region = !empty($form_state['values']['regions'][$theme->name]) ? $form_state['values']['regions'][$theme->name] : BLOCK_REGION_NONE;
  72. $query->values(array(
  73. 'visibility' => (int) $form_state['values']['visibility'],
  74. 'pages' => trim($form_state['values']['pages']),
  75. 'custom' => (int) $form_state['values']['custom'],
  76. 'title' => $form_state['values']['title'],
  77. 'module' => $form_state['values']['module'],
  78. 'theme' => $theme->name,
  79. 'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
  80. 'status' => 0,
  81. 'status' => (int) ($region != BLOCK_REGION_NONE),
  82. 'weight' => 0,
  83. 'delta' => $delta,
  84. 'cache' => DRUPAL_NO_CACHE,
  85. ));
  86. }
  87. }
  88. $query->execute();
  89. $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
  90. foreach (array_filter($form_state['values']['roles']) as $rid) {
  91. $query->values(array(
  92. 'rid' => $rid,
  93. 'module' => $form_state['values']['module'],
  94. 'delta' => $delta,
  95. ));
  96. }
  97. $query->execute();
  98. drupal_set_message(t('The block has been created.'));
  99. cache_clear_all();
  100. $form_state['redirect'] = 'admin/structure/block';
  101. }
  102. /**
  103. * Alters the block admin form to add delete links next to menu blocks.
  104. */
  105. function _menu_block_form_block_admin_display_form_alter(&$form, $form_state) {
  106. $blocks = module_invoke_all('menu_block_blocks');
  107. foreach (variable_get('menu_block_ids', array()) AS $delta) {
  108. if (empty($blocks[$delta])) {
  109. $form['blocks']['menu_block_' . $delta]['delete'] = array('#type' => 'link', '#title' => t('delete'), '#href' => 'admin/structure/block/delete-menu-block/' . $delta);
  110. }
  111. }
  112. if (variable_get('menu_block_suppress_core')) {
  113. foreach (array_keys(menu_get_menus(FALSE)) AS $delta) {
  114. if (empty($form['blocks']['menu_' . $delta]['region']['#default_value'])) {
  115. unset($form['blocks']['menu_' . $delta]);
  116. }
  117. }
  118. foreach (array_keys(menu_list_system_menus()) AS $delta) {
  119. if (empty($form['blocks']['system_' . $delta]['region']['#default_value'])) {
  120. unset($form['blocks']['system_' . $delta]);
  121. }
  122. }
  123. }
  124. }
  125. /**
  126. * Menu callback: confirm deletion of menu blocks.
  127. */
  128. function menu_block_delete($form, &$form_state, $delta = 0) {
  129. $title = _menu_block_format_title(menu_block_get_config($delta));
  130. $form['block_title'] = array('#type' => 'hidden', '#value' => $title);
  131. $form['delta'] = array('#type' => 'hidden', '#value' => $delta);
  132. return confirm_form($form, t('Are you sure you want to delete the "%name" block?', array('%name' => $title)), 'admin/structure/block', NULL, t('Delete'), t('Cancel'));
  133. }
  134. /**
  135. * Deletion of menu blocks.
  136. */
  137. function menu_block_delete_submit($form, &$form_state) {
  138. // Remove the menu block configuration variables.
  139. $delta = $form_state['values']['delta'];
  140. $block_ids = variable_get('menu_block_ids', array());
  141. unset($block_ids[array_search($delta, $block_ids)]);
  142. sort($block_ids);
  143. variable_set('menu_block_ids', $block_ids);
  144. variable_del("menu_block_{$delta}_title_link");
  145. variable_del("menu_block_{$delta}_admin_title");
  146. variable_del("menu_block_{$delta}_parent");
  147. variable_del("menu_block_{$delta}_level");
  148. variable_del("menu_block_{$delta}_follow");
  149. variable_del("menu_block_{$delta}_depth");
  150. variable_del("menu_block_{$delta}_expanded");
  151. variable_del("menu_block_{$delta}_sort");
  152. db_delete('block')
  153. ->condition('module', 'menu_block')
  154. ->condition('delta', $delta)
  155. ->execute();
  156. db_delete('block_role')
  157. ->condition('module', 'menu_block')
  158. ->condition('delta', $delta)
  159. ->execute();
  160. drupal_set_message(t('The block "%name" has been removed.', array('%name' => $form_state['values']['block_title'])));
  161. cache_clear_all();
  162. $form_state['redirect'] = 'admin/structure/block';
  163. return;
  164. }
  165. /**
  166. * Implements hook_block_info().
  167. */
  168. function _menu_block_block_info() {
  169. $blocks = array();
  170. $deltas = variable_get('menu_block_ids', array());
  171. foreach (array_keys(module_invoke_all('menu_block_blocks')) as $delta) {
  172. $deltas[] = $delta;
  173. }
  174. foreach ($deltas AS $delta) {
  175. $blocks[$delta]['info'] = _menu_block_format_title(menu_block_get_config($delta));
  176. // Menu blocks can't be cached because each menu item can have
  177. // a custom access callback. menu.inc manages its own caching.
  178. $blocks[$delta]['cache'] = DRUPAL_NO_CACHE;
  179. }
  180. return $blocks;
  181. }
  182. /**
  183. * Return the title of the block.
  184. *
  185. * @param $config
  186. * array The configuration of the menu block.
  187. * @return
  188. * string The title of the block.
  189. */
  190. function _menu_block_format_title($config) {
  191. // If an administrative title is specified, use it.
  192. if (!empty($config['admin_title'])) {
  193. return check_plain($config['admin_title']);
  194. }
  195. $menus = menu_block_get_all_menus();
  196. $menus[MENU_TREE__CURRENT_PAGE_MENU] = t('Current menu');
  197. if (empty($config['menu_name']) || empty($menus[$config['menu_name']])) {
  198. $title = t('Unconfigured menu block');
  199. }
  200. else {
  201. // Show the configured levels in the block info
  202. $replacements = array(
  203. '@menu_name' => $menus[$config['menu_name']],
  204. '@level1' => $config['level'],
  205. '@level2' => $config['level'] + $config['depth'] - 1,
  206. );
  207. if ($config['parent_mlid']) {
  208. $parent_item = menu_link_load($config['parent_mlid']);
  209. $replacements['@menu_name'] = $parent_item['title'];
  210. }
  211. if ($config['follow']) {
  212. $title = t('@menu_name (active menu item)', $replacements);
  213. }
  214. elseif ($config['depth'] == 1) {
  215. $title = t('@menu_name (level @level1)', $replacements);
  216. }
  217. elseif ($config['depth']) {
  218. if ($config['expanded']) {
  219. $title = t('@menu_name (expanded levels @level1-@level2)', $replacements);
  220. }
  221. else {
  222. $title = t('@menu_name (levels @level1-@level2)', $replacements);
  223. }
  224. }
  225. else {
  226. if ($config['expanded']) {
  227. $title = t('@menu_name (expanded levels @level1+)', $replacements);
  228. }
  229. else {
  230. $title = t('@menu_name (levels @level1+)', $replacements);
  231. }
  232. }
  233. }
  234. return $title;
  235. }
  236. /**
  237. * Implements hook_block_configure().
  238. */
  239. function _menu_block_block_configure($delta = '') {
  240. // Create a pseudo form state.
  241. $form_state = array('values' => menu_block_get_config($delta));
  242. return menu_block_configure_form(array(), $form_state);
  243. }
  244. /**
  245. * Returns the configuration form for a menu tree.
  246. *
  247. * @param $form_state
  248. * array An associated array of configuration options should be present in the
  249. * 'values' key. If none are given, default configuration is assumed.
  250. * @return
  251. * array The form in Form API format.
  252. */
  253. function menu_block_configure_form($form, &$form_state) {
  254. $config = array();
  255. // Get the config from the form state.
  256. if (!empty($form_state['values'])) {
  257. $config = $form_state['values'];
  258. if (!empty($config['parent'])) {
  259. list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent']);
  260. }
  261. }
  262. // Merge in the default configuration.
  263. $config += menu_block_get_config();
  264. // Don't display the config form if this delta is exported to code.
  265. if (!empty($config['exported_to_code'])) {
  266. $form['exported_message'] = array(
  267. '#markup' => '<p><em>' . t('Configuration is being provided by code.') . '</em></p>',
  268. );
  269. return $form;
  270. }
  271. // Build the standard form.
  272. $form['#attached']['js'][] = drupal_get_path('module', 'menu_block') . '/menu-block.js';
  273. $form['#attached']['css'][] = drupal_get_path('module', 'menu_block') . '/menu-block-admin.css';
  274. $form['#attached']['library'][] = array('system', 'ui.button');
  275. $form['menu-block-wrapper-start'] = array(
  276. '#markup' => '<div id="menu-block-settings">',
  277. '#weight' => -20,
  278. );
  279. $form['display_options'] = array(
  280. '#type' => 'radios',
  281. '#title' => t('Display'),
  282. '#default_value' => 'basic',
  283. '#options' => array(
  284. 'basic' => t('Basic options'),
  285. 'advanced' => t('Advanced options'),
  286. ),
  287. '#attributes' => array('class' => array('clearfix')),
  288. '#weight' => -19,
  289. );
  290. $form['title_link'] = array(
  291. '#type' => 'checkbox',
  292. '#title' => t('Block title as link'),
  293. '#default_value' => $config['title_link'],
  294. '#description' => t('Make the default block title a link to that menu item. An overridden block title will not be a link.'),
  295. '#states' => array(
  296. 'visible' => array(
  297. ':input[name=title]' => array('value' => ''),
  298. ),
  299. ),
  300. );
  301. // We need a different state if the form is in a Panel overlay.
  302. if (isset($form['override_title'])) {
  303. $form['title_link']['#states'] = array(
  304. 'visible' => array(
  305. ':input[name=override_title]' => array('checked' => FALSE),
  306. ),
  307. );
  308. }
  309. $form['admin_title'] = array(
  310. '#type' => 'textfield',
  311. '#default_value' => $config['admin_title'],
  312. '#title' => t('Administrative title'),
  313. '#description' => t('This title will be used administratively to identify this block. If blank, the regular title will be used.'),
  314. );
  315. $menus = menu_block_get_all_menus();
  316. $form['menu_name'] = array(
  317. '#type' => 'select',
  318. '#title' => t('Menu'),
  319. '#default_value' => $config['menu_name'],
  320. '#options' => $menus,
  321. '#description' => t('The preferred menus used by <em>&lt;the menu selected by the page&gt;</em> can be customized on the <a href="!url">Menu block settings page</a>.', array('!url' => url('admin/config/user-interface/menu-block'))),
  322. '#attributes' => array('class' => array('menu-block-menu-name')),
  323. );
  324. $form['level'] = array(
  325. '#type' => 'select',
  326. '#title' => t('Starting level'),
  327. '#default_value' => $config['level'],
  328. '#options' => array(
  329. '1' => t('1st level (primary)'),
  330. '2' => t('2nd level (secondary)'),
  331. '3' => t('3rd level (tertiary)'),
  332. '4' => t('4th level'),
  333. '5' => t('5th level'),
  334. '6' => t('6th level'),
  335. '7' => t('7th level'),
  336. '8' => t('8th level'),
  337. '9' => t('9th level'),
  338. ),
  339. '#description' => t('Blocks that start with the 1st level will always be visible. Blocks that start with the 2nd level or deeper will only be visible when the trail to the active menu item is in the block’s tree.'),
  340. );
  341. // The value of "follow" in the database/config array is either FALSE or the
  342. // value of the "follow_parent" form element.
  343. if ($follow = $config['follow']) {
  344. $follow_parent = $follow;
  345. $follow = 1;
  346. }
  347. else {
  348. $follow_parent = 'active';
  349. }
  350. $form['follow'] = array(
  351. '#type' => 'checkbox',
  352. '#title' => t('Make the starting level follow the active menu item.'),
  353. '#default_value' => $follow,
  354. '#description' => t('If the active menu item is deeper than the level specified above, the starting level will follow the active menu item. Otherwise, the starting level of the tree will remain fixed.'),
  355. '#element_validate' => array('menu_block_configure_form_follow_validate'),
  356. );
  357. $form['follow_parent'] = array(
  358. '#type' => 'select',
  359. '#title' => t('Starting level will be'),
  360. '#default_value' => $follow_parent,
  361. '#options' => array(
  362. 'active' => t('Active menu item'),
  363. 'child' => t('Children of active menu item'),
  364. ),
  365. '#description' => t('When following the active menu item, specify if the starting level should be the active menu item or its children.'),
  366. '#states' => array(
  367. 'visible' => array(
  368. ':input[name=follow]' => array('checked' => TRUE),
  369. ),
  370. ),
  371. );
  372. $form['depth'] = array(
  373. '#type' => 'select',
  374. '#title' => t('Maximum depth'),
  375. '#default_value' => $config['depth'],
  376. '#options' => array(
  377. '1' => '1',
  378. '2' => '2',
  379. '3' => '3',
  380. '4' => '4',
  381. '5' => '5',
  382. '6' => '6',
  383. '7' => '7',
  384. '8' => '8',
  385. '9' => '9',
  386. '0' => t('Unlimited'),
  387. ),
  388. '#description' => t('From the starting level, specify the maximum depth of the menu tree.'),
  389. );
  390. $form['expanded'] = array(
  391. '#type' => 'checkbox',
  392. '#title' => t('<strong>Expand all children</strong> of this tree.'),
  393. '#default_value' => $config['expanded'],
  394. );
  395. $form['sort'] = array(
  396. '#type' => 'checkbox',
  397. '#title' => t('<strong>Sort</strong> menu tree by the active menu item’s trail.'),
  398. '#default_value' => $config['sort'],
  399. '#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'),
  400. );
  401. $form['parent_mlid'] = array(
  402. '#type' => 'select',
  403. '#title' => t('Fixed parent item'),
  404. '#default_value' => $config['menu_name'] . ':' . $config['parent_mlid'],
  405. '#options' => menu_parent_options($menus, array('mlid' => 0)),
  406. '#description' => t('Alter the “starting level” and “maximum depth” options to be relative to the fixed parent item. The tree of links will only contain children of the selected menu item.'),
  407. '#attributes' => array('class' => array('menu-block-parent-mlid')),
  408. '#element_validate' => array('menu_block_configure_form_parent_validate'),
  409. );
  410. $form['parent_mlid']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>';
  411. $form['menu-block-wrapper-close'] = array('#markup' => '</div>');
  412. // Set visibility of advanced options.
  413. foreach (array('title_link', 'follow', 'follow_parent', 'expanded', 'sort', 'parent_mlid') as $key) {
  414. $form[$key]['#states']['visible'][':input[name=display_options]'] = array('value' => 'advanced');
  415. }
  416. if ($config['title_link'] || $follow || $config['expanded'] || $config['sort'] || $config['parent_mlid']) {
  417. $form['display_options']['#default_value'] = 'advanced';
  418. }
  419. return $form;
  420. }
  421. /**
  422. * Validates the parent element of the block configuration form.
  423. */
  424. function menu_block_configure_form_parent_validate($element, &$form_state) {
  425. // Determine the fixed parent item's menu and mlid.
  426. list($menu_name, $parent_mlid) = explode(':', $form_state['values']['parent_mlid']);
  427. if ($parent_mlid) {
  428. // If mlid is set, its menu overrides the menu_name option.
  429. $form_state['values']['menu_name'] = $menu_name;
  430. }
  431. else {
  432. // Otherwise the menu_name overrides the parent item option.
  433. $form_state['values']['parent_mlid'] = $menu_name . ':0';
  434. }
  435. // The value of "parent" stored in the database/config array is the menu name
  436. // combined with the optional parent menu item's mlid.
  437. $form_state['values']['parent'] = $form_state['values']['parent_mlid'];
  438. }
  439. /**
  440. * Validates the follow element of the block configuration form.
  441. */
  442. function menu_block_configure_form_follow_validate($element, &$form_state) {
  443. // The value of "follow" stored in the database/config array is either FALSE
  444. // or the value of the "follow_parent" form element.
  445. if ($form_state['values']['follow'] && !empty($form_state['values']['follow_parent'])) {
  446. $form_state['values']['follow'] = $form_state['values']['follow_parent'];
  447. }
  448. }
  449. /**
  450. * Implements hook_block_save().
  451. */
  452. function _menu_block_block_save($delta = '', $edit = array()) {
  453. if (!empty($delta)) {
  454. // Don't save values for an exported block.
  455. $config = menu_block_get_config($delta);
  456. if (empty($config['exported_to_code'])) {
  457. variable_set("menu_block_{$delta}_title_link", $edit['title_link']);
  458. variable_set("menu_block_{$delta}_admin_title", $edit['admin_title']);
  459. variable_set("menu_block_{$delta}_parent", $edit['parent']);
  460. variable_set("menu_block_{$delta}_level", $edit['level']);
  461. variable_set("menu_block_{$delta}_follow", $edit['follow']);
  462. variable_set("menu_block_{$delta}_depth", $edit['depth']);
  463. variable_set("menu_block_{$delta}_expanded", $edit['expanded']);
  464. variable_set("menu_block_{$delta}_sort", $edit['sort']);
  465. }
  466. }
  467. }
  468. /**
  469. * Menu callback: admin settings form.
  470. *
  471. * @return
  472. * The settings form used by Menu block.
  473. */
  474. function menu_block_admin_settings_form($form, &$form_state) {
  475. // Option to suppress core's blocks of menus.
  476. $form['menu_block_suppress_core'] = array(
  477. '#type' => 'checkbox',
  478. '#title' => t('Suppress Drupal’s standard menu blocks'),
  479. '#default_value' => variable_get('menu_block_suppress_core', 0),
  480. '#description' => t('On the blocks admin page, hide Drupal’s standard blocks of menus.'),
  481. '#access' => module_exists('block'),
  482. );
  483. // Retrieve core's menus.
  484. $menus = menu_get_menus();
  485. // Retrieve all the menu names provided by hook_menu_block_get_sort_menus().
  486. $menus = array_merge($menus, module_invoke_all('menu_block_get_sort_menus'));
  487. asort($menus);
  488. // Load stored configuration.
  489. $menu_order = variable_get('menu_block_menu_order', array('main-menu' => '', 'user-menu' => ''));
  490. // Remove any menus no longer in the list of all menus.
  491. foreach (array_keys($menu_order) as $menu) {
  492. if (!isset($menus[$menu])) {
  493. unset($menu_order[$menu]);
  494. }
  495. }
  496. // Merge the saved configuration with any un-configured menus.
  497. $all_menus = $menu_order + $menus;
  498. $form['heading'] = array(
  499. '#markup' => '<p>' . t('If a block is configured to use <em>"the menu selected by the page"</em>, the block will be generated from the first "available" menu that contains a link to the page.') . '</p>',
  500. );
  501. // Orderable list of menu selections.
  502. $form['menu_order'] = array(
  503. '#tree' => TRUE,
  504. '#theme' => 'menu_block_menu_order',
  505. );
  506. $order = 0;
  507. $total_menus = count($all_menus);
  508. foreach (array_keys($all_menus) as $menu_name) {
  509. $form['menu_order'][$menu_name] = array(
  510. 'title' => array(
  511. '#markup' => check_plain($menus[$menu_name]),
  512. ),
  513. 'available' => array(
  514. '#type' => 'checkbox',
  515. '#attributes' => array('title' => t('Select from the @menu_name menu', array('@menu_name' => $menus[$menu_name]))),
  516. '#default_value' => isset($menu_order[$menu_name]),
  517. ),
  518. 'weight' => array(
  519. '#type' => 'weight',
  520. '#default_value' => $order - $total_menus,
  521. '#delta' => $total_menus,
  522. '#id' => 'edit-menu-block-menus-' . $menu_name,
  523. ),
  524. );
  525. $order++;
  526. }
  527. $form['footer_note'] = array(
  528. '#markup' => '<p>' . t('The above list will <em>not</em> affect menu blocks that are configured to use a specific menu.') . '</p>',
  529. );
  530. $form['submit'] = array(
  531. '#type' => 'submit',
  532. '#value' => t('Save configuration'),
  533. );
  534. return $form;
  535. }
  536. /**
  537. * Form submission handler.
  538. */
  539. function menu_block_admin_settings_form_submit($form, &$form_state) {
  540. $menu_order = array();
  541. foreach ($form_state['values']['menu_order'] AS $menu_name => $row) {
  542. if ($row['available']) {
  543. // Add available menu and its weight to list.
  544. $menu_order[$menu_name] = (int) $row['weight'];
  545. }
  546. }
  547. // Sort the keys by the weight stored in the value.
  548. asort($menu_order);
  549. foreach ($menu_order AS $menu_name => $weight) {
  550. // Now that the array is sorted, the weight is redundant data.
  551. $menu_order[$menu_name] = '';
  552. }
  553. variable_set('menu_block_menu_order', $menu_order);
  554. if ($form_state['values']['menu_block_suppress_core']) {
  555. variable_set('menu_block_suppress_core', 1);
  556. }
  557. else {
  558. variable_del('menu_block_suppress_core');
  559. }
  560. drupal_set_message(t('The configuration options have been saved.'));
  561. }
  562. /**
  563. * Theme a drag-to-reorder table of menu selection checkboxes.
  564. */
  565. function theme_menu_block_menu_order($variables) {
  566. $element = $variables['element'];
  567. drupal_add_tabledrag('menu-block-menus', 'order', 'sibling', 'menu-weight');
  568. $variables = array(
  569. 'header' => array(
  570. t('Menu'),
  571. t('Available'),
  572. t('Weight'),
  573. ),
  574. 'rows' => array(),
  575. 'attributes' => array('id' => 'menu-block-menus'),
  576. );
  577. // Generate table of draggable menu names.
  578. foreach (element_children($element) as $menu_name) {
  579. $element[$menu_name]['weight']['#attributes']['class'] = array('menu-weight');
  580. $variables['rows'][] = array(
  581. 'data' => array(
  582. drupal_render($element[$menu_name]['title']),
  583. drupal_render($element[$menu_name]['available']),
  584. drupal_render($element[$menu_name]['weight']),
  585. ),
  586. 'class' => array('draggable'),
  587. );
  588. }
  589. return theme('table', $variables);
  590. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.