variable_admin.module 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Variable API module - Admin UI
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function variable_admin_menu() {
  10. $items['admin/config/system/variable'] = array(
  11. 'title' => 'Variables',
  12. 'description' => 'Variable settings for mixed modules.',
  13. 'page callback' => 'variable_admin_page_group',
  14. 'file' => 'variable_admin.inc',
  15. 'access arguments' => array('administer site configuration'),
  16. );
  17. $items['admin/config/system/variable/group'] = array(
  18. 'title' => 'Groups',
  19. 'description' => 'Variables per group.',
  20. 'type' => MENU_DEFAULT_LOCAL_TASK,
  21. );
  22. $items['admin/config/system/variable/module'] = array(
  23. 'title' => 'Modules',
  24. 'description' => 'Variables per module.',
  25. 'page callback' => 'variable_admin_page_module',
  26. 'file' => 'variable_admin.inc',
  27. 'access arguments' => array('administer site configuration'),
  28. 'type' => MENU_LOCAL_TASK,
  29. );
  30. $items['admin/config/system/variable/edit/%'] = array(
  31. 'title' => 'Edit variable',
  32. 'page callback' => 'drupal_get_form',
  33. 'page arguments' => array('variable_edit_form', 5),
  34. 'access callback' => 'variable_access',
  35. 'access arguments' => array(5),
  36. );
  37. if (module_exists('variable_realm')) {
  38. $items['admin/config/system/variable/realm'] = array(
  39. 'title' => 'Realms',
  40. 'description' => 'Configure realms.',
  41. 'page callback' => 'drupal_get_form',
  42. 'page arguments' => array('variable_admin_realm_overview'),
  43. 'file' => 'variable_admin.inc',
  44. 'access arguments' => array('administer site configuration'),
  45. 'type' => MENU_LOCAL_TASK,
  46. );
  47. $items['admin/config/system/variable/realm/overview'] = array(
  48. 'title' => 'Overview',
  49. 'description' => 'Configure realms.',
  50. 'type' => MENU_DEFAULT_LOCAL_TASK,
  51. 'weight' => -10
  52. );
  53. $weight = 0;
  54. foreach (variable_realm_list_all() as $realm => $controller) {
  55. $items['admin/config/system/variable/realm/' . $realm] = array(
  56. 'title callback' => 'variable_admin_realm_title',
  57. 'title arguments' => array($realm),
  58. 'description' => 'Configure realm variables.',
  59. 'page callback' => 'variable_admin_realm_info',
  60. 'page arguments' => array($realm),
  61. 'access callback' => 'variable_admin_realm_access',
  62. 'access arguments' => array($realm),
  63. 'file' => 'variable_admin.inc',
  64. 'type' => MENU_LOCAL_TASK,
  65. 'weight' => $weight++,
  66. );
  67. }
  68. $items['admin/config/system/variable/realm/%/edit'] = array(
  69. 'title' => 'Edit',
  70. 'description' => 'Edit realm variables.',
  71. 'page callback' => 'variable_admin_realm_edit',
  72. 'page arguments' => array(5),
  73. 'access callback' => 'variable_admin_realm_access',
  74. 'access arguments' => array(5, 'select'),
  75. 'file' => 'variable_admin.inc',
  76. );
  77. $items['admin/config/system/variable/realm/%/configure'] = array(
  78. 'title' => 'Configure',
  79. 'description' => 'Configure realm variables.',
  80. 'page callback' => 'drupal_get_form',
  81. 'page arguments' => array('variable_realm_select_variables_form', 5),
  82. 'access callback' => 'variable_admin_realm_access',
  83. 'access arguments' => array(5, 'select'),
  84. 'file' => 'variable_realm.form.inc',
  85. 'file path' => drupal_get_path('module', 'variable_realm'),
  86. );
  87. }
  88. return $items;
  89. }
  90. /**
  91. * Check permission for administering realm
  92. */
  93. function variable_admin_realm_access($realm_name, $property = 'title') {
  94. if ($info = variable_realm_info($realm_name)) {
  95. return !empty($info[$property]) && user_access('administer site configuration');
  96. }
  97. }
  98. /**
  99. * Retrieve title of given realm.
  100. */
  101. function variable_admin_realm_title($realm) {
  102. $info = variable_realm_info($realm);
  103. return isset($info['title']) ? $info['title'] : $realm;
  104. }