menu_editor.module 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Implementation of hook_menu().
  4. */
  5. function menu_editor_menu() {
  6. $items['admin/structure/menu/manage/%menu/poweredit'] = array(
  7. 'title' => 'Power Edit',
  8. 'page callback' => 'drupal_get_form',
  9. 'page arguments' => array('menu_editor_overview_form', 4),
  10. // 'title callback' => 'menu_editor_overview_title',
  11. // 'title arguments' => array(3),
  12. 'access callback' => 'menu_editor_form_access',
  13. 'access arguments' => array(4),
  14. 'type' => MENU_LOCAL_TASK,
  15. 'file' => 'menu_editor.admin.inc',
  16. );
  17. return $items;
  18. }
  19. /**
  20. * Implements hook_permission().
  21. */
  22. function menu_editor_permission() {
  23. $menus = menu_get_menus(TRUE);
  24. $perm = array();
  25. foreach ($menus as $menu_machine_name => $menu_display_name) {
  26. $perm["menu edit $menu_machine_name"] = array(
  27. 'title' => t("Menu editor: Edit @menu", array('@menu' => $menu_display_name)),
  28. );
  29. }
  30. return $perm;
  31. }
  32. /**
  33. * @param array $menu
  34. *
  35. * @return bool
  36. */
  37. function menu_editor_form_access($menu) {
  38. return
  39. user_access('administer menu') ||
  40. user_access("menu edit $menu[menu_name]")
  41. ;
  42. }
  43. // function menu_editor_admin_menu() {
  44. // $result = db_query("SELECT * FROM {menu_custom} ORDER BY title");
  45. // $items = array();
  46. // while ($menu = db_fetch_array($result)) {
  47. // $items[] = array(
  48. // 'title' => $menu['title'],
  49. // 'path' => 'admin/build/menu-customize/'. $menu['menu_name'] . '/poweredit',
  50. // 'parent_path' => 'admin/build/menu/list',
  51. // 'weight' => 100,
  52. // );
  53. // }
  54. // return $items;
  55. // }
  56. /**
  57. * Implements hook_theme().
  58. *
  59. * @return array[]
  60. */
  61. function menu_editor_theme() {
  62. return array(
  63. 'menu_editor_overview_form' => array(
  64. 'file' => 'menu_editor.admin.inc',
  65. 'render element' => 'form',
  66. ),
  67. );
  68. }
  69. /**
  70. * Title callback for the menu overview page and links.
  71. *
  72. * @param array $menu
  73. *
  74. * @return string
  75. */
  76. function menu_editor_overview_title(array $menu) {
  77. return $menu['title'];
  78. }
  79. /**
  80. * @return string[]
  81. */
  82. function menu_editor_get_placeholders() {
  83. static $placeholders;
  84. if (!isset($placeholders)) {
  85. /* @see hook_menu_editor_placeholders() */
  86. $placeholders = module_invoke_all('menu_editor_placeholders');
  87. }
  88. return $placeholders;
  89. }
  90. /**
  91. * @param string $placeholder
  92. * @param string|int $mlid
  93. *
  94. * @return string
  95. */
  96. function menu_editor_get_path_for_placeholder($placeholder, $mlid) {
  97. $placeholders = menu_editor_get_placeholders();
  98. if (isset($placeholders[$placeholder])) {
  99. return str_replace('%mlid', $mlid, $placeholders[$placeholder]);
  100. }
  101. return $placeholder;
  102. }