variable_admin.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @file
  4. * Variable API module - Admin UI
  5. */
  6. /**
  7. * Variable overview, by group
  8. */
  9. function variable_admin_page_group($group = NULL) {
  10. variable_include();
  11. $build['message']['#markup'] = _variable_admin_realm_message();
  12. $realm_options = _variable_admin_realm_options();
  13. if ($group && ($group_info = variable_get_group($group))) {
  14. $group_info += array('description' => '');
  15. drupal_set_title($group_info['title']);
  16. $list = variable_list_group($group);
  17. $build['description']['#markup'] = '<h3>' . $group_info['description'] . '</h3>';
  18. $build['form'] = drupal_get_form('variable_edit_form', array_keys($list), $realm_options);
  19. return $build;
  20. }
  21. else {
  22. // Groups overview
  23. $build['groups'] = array(
  24. '#type' => 'vertical_tabs',
  25. );
  26. foreach (variable_get_group() as $group => $info) {
  27. if ($group_variables = variable_list_group($group)) {
  28. $build['groups'][$group] = array(
  29. '#type' => 'fieldset',
  30. '#title' => $info['title'],
  31. '#collapsible' => TRUE, '#collapsed' => TRUE,
  32. '#description' => (!empty($info['description']) ? $info['description'] . ' ' : '') . l(t('Edit group variables'), 'admin/config/system/variable/group/' . $group),
  33. );
  34. $build['groups'][$group]['list'] = variable_admin_group_list($group_variables, $realm_options);
  35. }
  36. }
  37. return $build;
  38. }
  39. }
  40. /**
  41. * Build list of variables for group
  42. *
  43. * @return Renderable array
  44. */
  45. function variable_admin_group_list($variables, $options = array()) {
  46. $list = array();
  47. foreach ($variables as $name => $variable) {
  48. $type = variable_get_type($variable['type']);
  49. $list[$name] = array(
  50. '#type' => 'item',
  51. '#title' => l($variable['title'], 'admin/config/system/variable/edit/' . $name) . ' (' . $type['title'] . ')',
  52. '#markup' => variable_format_value($variable, $options), //
  53. '#description' => isset($variable['description']) ? $variable['description'] : '',
  54. );
  55. }
  56. return $list;
  57. return array(
  58. '#theme' => 'table',
  59. '#rows' => $list,
  60. );
  61. }
  62. /**
  63. * Variable overview, by group
  64. */
  65. function variable_admin_page_module($name = NULL) {
  66. variable_include();
  67. $build['message']['#markup'] = _variable_admin_realm_message();
  68. $realm_options = _variable_admin_realm_options();
  69. if ($name && (in_array($name, module_list()))) {
  70. $modules = system_list('module_enabled');
  71. $module = $modules[$name];
  72. drupal_set_title($module->info['name']);
  73. $list = variable_list_module($name);
  74. $build['description']['#markup'] = $module->info['description'];
  75. $build['form'] = drupal_get_form('variable_edit_form', array_keys($list), $realm_options);
  76. return $build;
  77. }
  78. else {
  79. // Groups overview
  80. $build['modules'] = array(
  81. '#type' => 'vertical_tabs',
  82. );
  83. foreach (system_list('module_enabled') as $module) {
  84. if ($variables = variable_list_module($module->name)) {
  85. $build['modules'][$module->name] = array(
  86. '#type' => 'fieldset',
  87. '#title' => $module->info['name'],
  88. '#collapsible' => TRUE, '#collapsed' => TRUE,
  89. '#description' => $module->info['description'] . ' ' . l(t('Edit module variables'), 'admin/config/system/variable/module/' . $module->name),
  90. '#group' => 'modules',
  91. );
  92. $build['modules'][$module->name]['list'] = variable_admin_group_list($variables, $realm_options);
  93. }
  94. }
  95. return $build;
  96. }
  97. }
  98. /**
  99. * Lists available realms.
  100. */
  101. function variable_admin_realm_overview($form, $form_state) {
  102. $header = array(
  103. t('Realm name'),
  104. t('Weight'),
  105. t('Options'),
  106. );
  107. $realms = array();
  108. foreach (variable_realm_info() as $realm => $info) {
  109. $options = array();
  110. // Add list of configured variables + configuration link
  111. if (!empty($info['select'])) {
  112. $options[] = l(t('Configure'), 'admin/config/system/variable/realm/' . $realm . '/configure');
  113. $options[] = l(t('Edit'), 'admin/config/system/variable/realm/' . $realm . '/edit');
  114. }
  115. // Get weight from realm controller.
  116. $controller = variable_realm_controller($realm);
  117. $realms[] = array(
  118. l($info['title'], 'admin/config/system/variable/realm/' . $realm),
  119. $controller->getDefaultWeight(),
  120. implode(' | ' , $options)
  121. );
  122. }
  123. $form['realms'] = array(
  124. '#theme' => 'table',
  125. '#header' => $header,
  126. '#rows' => $realms,
  127. '#empty' => t('No realms available.'),
  128. );
  129. return $form;
  130. }
  131. /**
  132. * Lists available realms.
  133. */
  134. function variable_admin_realm_info($realm_name) {
  135. $controller = variable_realm_controller($realm_name);
  136. $build['title'] = array(
  137. '#type' => 'item',
  138. '#title' => t('Name'),
  139. '#markup' => $controller->getTitle(),
  140. );
  141. $build['keys'] = array(
  142. '#theme' => 'item_list',
  143. '#title' => t('Keys'),
  144. '#items' => $controller->getAllKeys(),
  145. );
  146. $build['variables'] = array(
  147. '#theme' => 'item_list',
  148. '#title' => t('Variables'),
  149. '#items' => $controller->getEnabledVariables(),
  150. );
  151. if ($controller->getInfo('select')) {
  152. $build['options'] = array(
  153. '#theme' => 'item_list',
  154. '#title' => t('Options'),
  155. '#items' => array(
  156. l(t('Configure'), 'admin/config/system/variable/realm/' . $realm_name . '/configure'),
  157. l(t('Edit'), 'admin/config/system/variable/realm/' . $realm_name . '/edit'),
  158. ),
  159. );
  160. }
  161. return $build;
  162. }
  163. /**
  164. * Edit variables for realm.
  165. */
  166. function variable_admin_realm_edit($realm_name) {
  167. module_load_include('form.inc', 'variable_realm');
  168. $realm_key = variable_realm_form_key_current($realm_name);
  169. $build['select'] = variable_realm_form_key_selector($realm_name, $realm_key);
  170. $build['form'] = drupal_get_form('variable_realm_edit_variables_form', $realm_name, $realm_key);
  171. return $build;
  172. }
  173. /**
  174. * Message for forms viewing / editing global variables.
  175. */
  176. function _variable_admin_realm_message() {
  177. if (module_exists('variable_realm')) {
  178. return '<p>' . t('These are global default variables. To edit variables for a specific realm go to <a href="@variable-realm">Variable Realms</a>', array('@variable-realm' => url('admin/config/system/variable/realm'))) .'</p>';
  179. }
  180. else {
  181. return '';
  182. }
  183. }
  184. /**
  185. * Options for forms viewing / editing global variables.
  186. */
  187. function _variable_admin_realm_options() {
  188. if (module_exists('variable_realm')) {
  189. $options['realm'] = variable_realm('global', 'default');
  190. $options['realm_name'] = 'global';
  191. $options['realm_key'] = 'default';
  192. return $options;
  193. }
  194. else {
  195. return array();
  196. }
  197. }