views_ui.module

  1. 3.x views_ui.module
  2. 2.x views_ui.module

views_ui.module Provide structure for the administrative interface to Views.

File

views_ui.module
View source
  1. <?php
  2. /**
  3. * @file views_ui.module
  4. * Provide structure for the administrative interface to Views.
  5. */
  6. /*
  7. * Implementation of hook_menu()
  8. */
  9. function views_ui_menu() {
  10. $items = array();
  11. // Minor code reduction technique
  12. $base = array(
  13. 'access callback' => 'user_access',
  14. 'access arguments' => array('administer views'),
  15. 'file' => 'includes/admin.inc',
  16. );
  17. $callback = $base + array('type' => MENU_CALLBACK);
  18. $convert = array('file' => 'includes/convert.inc') + $base;
  19. $items['admin/build/views'] = $base + array(
  20. 'title' => 'Views',
  21. 'page callback' => 'views_ui_list_views',
  22. 'description' => 'Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.',
  23. 'type' => MENU_NORMAL_ITEM
  24. );
  25. $items['admin/build/views/list'] = $base + array(
  26. 'title' => 'List',
  27. 'page callback' => 'views_ui_list_views',
  28. 'type' => MENU_DEFAULT_LOCAL_TASK,
  29. 'weight' => '-1'
  30. );
  31. $items['admin/build/views/add'] = $base + array(
  32. 'title' => 'Add',
  33. 'page callback' => 'views_ui_add_page',
  34. 'type' => MENU_LOCAL_TASK
  35. );
  36. $items['admin/build/views/import'] = array(
  37. 'title' => 'Import',
  38. 'page callback' => 'drupal_get_form',
  39. 'page arguments' => array('views_ui_import_page'),
  40. 'access callback' => 'views_import_access',
  41. 'type' => MENU_LOCAL_TASK
  42. ) + $base;
  43. $items['admin/build/views/tools'] = $base + array(
  44. 'title' => 'Tools',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => array('views_ui_admin_tools'),
  47. 'type' => MENU_LOCAL_TASK
  48. );
  49. $items['admin/build/views/tools/basic'] = $base + array(
  50. 'title' => 'Basic',
  51. 'page callback' => 'drupal_get_form',
  52. 'page arguments' => array('views_ui_admin_tools'),
  53. 'type' => MENU_DEFAULT_LOCAL_TASK,
  54. 'weight' => -10,
  55. );
  56. $items['admin/build/views/tools/convert'] = $convert + array(
  57. 'title' => 'Convert',
  58. 'description' => 'Convert stored Views 1 views.',
  59. 'page callback' => 'views_ui_admin_convert',
  60. 'type' => MENU_LOCAL_TASK,
  61. 'weight' => 1,
  62. );
  63. $items['admin/build/views1/delete'] = $convert + array(
  64. 'title' => 'Delete view',
  65. 'page callback' => 'drupal_get_form',
  66. 'page arguments' => array('views_ui_delete1_confirm', 4),
  67. 'type' => MENU_CALLBACK,
  68. );
  69. $items['admin/build/views1/convert'] = $convert + array(
  70. 'title' => 'Convert view',
  71. 'page callback' => 'views_ui_convert1',
  72. 'page arguments' => array(4),
  73. 'type' => MENU_CALLBACK,
  74. );
  75. $items['admin/build/views/delete/%views_ui_cache'] = $callback + array(
  76. 'title' => 'Delete view',
  77. 'page callback' => 'drupal_get_form',
  78. 'page arguments' => array('views_ui_delete_confirm', 4),
  79. );
  80. $items['admin/build/views/break-lock/%views_ui_cache'] = $callback + array(
  81. 'title' => 'Delete view',
  82. 'page callback' => 'drupal_get_form',
  83. 'page arguments' => array('views_ui_break_lock_confirm', 4),
  84. );
  85. $items['admin/build/views/export/%views_ui_cache'] = $callback + array(
  86. 'page callback' => 'drupal_get_form',
  87. 'page arguments' => array('views_ui_export_page', 4),
  88. 'type' => MENU_LOCAL_TASK
  89. );
  90. $items['admin/build/views/clone/%views_ui_cache'] = $callback + array(
  91. 'page callback' => 'views_ui_clone_page',
  92. 'page arguments' => array(4),
  93. 'type' => MENU_LOCAL_TASK
  94. );
  95. $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
  96. 'page callback' => 'views_ui_enable_page',
  97. 'page arguments' => array(4),
  98. );
  99. $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
  100. 'page callback' => 'views_ui_disable_page',
  101. 'page arguments' => array(4),
  102. );
  103. // Many line items for editing a view.
  104. $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
  105. 'title' => 'Edit',
  106. 'page callback' => 'views_ui_edit_page',
  107. 'page arguments' => array(4),
  108. 'type' => MENU_LOCAL_TASK
  109. );
  110. // lots of little edit form pieces.
  111. $items['admin/build/views/%views_ui_js/analyze/%views_ui_cache'] = $callback + array(
  112. 'page callback' => 'views_ui_analyze_view',
  113. 'page arguments' => array(3, 5),
  114. );
  115. $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array(
  116. 'page callback' => 'views_ui_edit_details',
  117. 'page arguments' => array(3, 5),
  118. );
  119. $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
  120. 'page callback' => 'views_ui_add_display',
  121. 'page arguments' => array(3, 5),
  122. );
  123. $items['admin/build/views/%views_ui_js/clone-display/%views_ui_cache'] = $callback + array(
  124. 'page callback' => 'views_ui_clone_display',
  125. 'page arguments' => array(3, 5, 6),
  126. );
  127. // Live preview
  128. $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
  129. 'page callback' => 'views_ui_preview',
  130. 'page arguments' => array(3, 5),
  131. );
  132. // autocompletes for handlers and such
  133. $items['admin/views/ajax/autocomplete/tag'] = $callback + array(
  134. 'page callback' => 'views_ui_autocomplete_tag',
  135. );
  136. // Generic ajax callback
  137. // display specific parameters
  138. $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
  139. 'page callback' => 'views_ui_ajax_form',
  140. 'page arguments' => array(3, 4, 5),
  141. );
  142. return $items;
  143. }
  144. /*
  145. * Implementation of hook_help()
  146. */
  147. function views_ui_help($path, $arg = '') {
  148. switch ($path) {
  149. case 'admin/build/views/tools/convert':
  150. return '<p>' . t('The converter will make a best-effort attempt to convert a Views 1 view to Views 2. This conversion is not reliable; you will very likely have to make adjustments to your view to get it to match. You can import Views 1 views through the normal Import tab.') . '</p>';
  151. }
  152. }
  153. /*
  154. * Implementation of hook_theme()
  155. */
  156. function views_ui_theme() {
  157. $path = drupal_get_path('module', 'views');
  158. require_once "./$path/includes/admin.inc";
  159. return array(
  160. // edit a view
  161. 'views_ui_edit_view' => array(
  162. 'arguments' => array('view' => NULL),
  163. 'template' => 'views-ui-edit-view',
  164. 'path' => "$path/theme",
  165. ),
  166. 'views_ui_edit_tab' => array(
  167. 'arguments' => array('view' => NULL, 'display' => NULL),
  168. 'template' => 'views-ui-edit-tab',
  169. 'path' => "$path/theme",
  170. ),
  171. 'views_ui_edit_item' => array(
  172. 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE),
  173. 'template' => 'views-ui-edit-item',
  174. 'path' => "$path/theme",
  175. ),
  176. 'views_ui_rearrange_form' => array(
  177. 'arguments' => array('form' => NULL),
  178. 'file' => 'includes/admin.inc',
  179. ),
  180. // list views
  181. 'views_ui_list_views' => array(
  182. 'template' => 'views-ui-list-views',
  183. 'path' => "$path/theme",
  184. ),
  185. 'views_ui_list_views_form' => array(
  186. 'file' => 'includes/admin.inc',
  187. 'arguments' => array('form' => NULL),
  188. ),
  189. // tab themes
  190. 'views_tabset' => array(
  191. 'arguments' => array('tabs' => NULL),
  192. 'file' => 'includes/tabs.inc',
  193. ),
  194. 'views_tab' => array(
  195. 'arguments' => array('body' => NULL),
  196. 'file' => 'includes/tabs.inc',
  197. ),
  198. // On behalf of a plugin
  199. 'views_ui_style_plugin_table' => array(
  200. 'arguments' => array('form' => NULL),
  201. 'file' => 'includes/admin.inc',
  202. ),
  203. );
  204. }
  205. /**
  206. * Specialized menu callback to load a view either out of the cache or just
  207. * load it.
  208. */
  209. function views_ui_cache_load($name) {
  210. views_include('cache');
  211. views_include('view');
  212. $view = views_object_cache_get('view', $name);
  213. if (empty($view)) {
  214. $view = views_get_view($name);
  215. if (!empty($view)) {
  216. // Check to see if someone else is already editing this view.
  217. global $user;
  218. $view->locked = db_fetch_object(db_query("SELECT s.uid, v.updated FROM {views_object_cache} v INNER JOIN {sessions} s ON v.sid = s.sid WHERE s.sid != '%s' and v.name = '%s' and v.obj = 'view' ORDER BY v.updated ASC", session_id(), $view->name));
  219. }
  220. }
  221. if (empty($view)) {
  222. return FALSE;
  223. }
  224. else {
  225. return $view;
  226. }
  227. }
  228. function views_ui_check_lock($view) {
  229. }
  230. /**
  231. * Specialized cache function to add a flag to our view, include an appropriate
  232. * include, and cache more easily.
  233. */
  234. function views_ui_cache_set(&$view) {
  235. if (!empty($view->locked)) {
  236. drupal_set_message(t('Changes cannot be made to a locked view.'), 'error');
  237. return;
  238. }
  239. views_include('cache');
  240. $view->changed = TRUE; // let any future object know that this view has changed.
  241. // Unset handlers; we don't want to write these into the cache
  242. unset($view->display_handler);
  243. unset($view->current_display);
  244. unset($view->default_display);
  245. foreach (array_keys($view->display) as $id) {
  246. unset($view->display[$id]->handler);
  247. unset($view->display[$id]->default_display);
  248. }
  249. views_object_cache_set('view', $view->name, $view);
  250. }
  251. /**
  252. * Specialized menu callback to load a view that is only a default
  253. * view.
  254. */
  255. function views_ui_default_load($name) {
  256. $view = views_get_view($name);
  257. if ($view->type == t('Default')) {
  258. return $view;
  259. }
  260. return FALSE;
  261. }
  262. /**
  263. * Check to see if the incoming menu item is js capable or not.
  264. */
  265. function views_ui_js_load($js) {
  266. if ($js == 'ajax') {
  267. return TRUE;
  268. }
  269. return 0;
  270. }