Added a bit of help to the converter
[project/views.git] / views_ui.module
1 <?php
2 // $Id$
3
4 /**
5 * @file views_ui.module
6 *
7 * Provide structure for the administrative interface to Views.
8 */
9
10 function views_ui_menu() {
11 $items = array();
12
13 // Minor code reduction technique
14 $base = array(
15 'access callback' => 'user_access',
16 'access arguments' => array('administer views'),
17 'file' => 'includes/admin.inc',
18 );
19
20 $callback = $base + array('type' => MENU_CALLBACK);
21
22 $items['admin/build/views'] = $base + array(
23 'title' => t('Views'),
24 'page callback' => 'views_ui_list_views',
25 'description' => t('Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.'),
26 'type' => MENU_NORMAL_ITEM
27 );
28 $items['admin/build/views/list'] = $base + array(
29 'title' => t('List'),
30 'page callback' => 'views_ui_list_views',
31 'type' => MENU_DEFAULT_LOCAL_TASK,
32 'weight' => '-1'
33 );
34 $items['admin/build/views/add'] = $base + array(
35 'title' => t('Add'),
36 'page callback' => 'views_ui_add_page',
37 'type' => MENU_LOCAL_TASK
38 );
39 $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
40 'title' => t('Edit'),
41 'page callback' => 'views_ui_edit_page',
42 'page arguments' => array(4),
43 'type' => MENU_LOCAL_TASK
44 );
45 $items['admin/build/views/import'] = $base + array(
46 'title' => t('Import'),
47 'page callback' => 'drupal_get_form',
48 'page arguments' => array('views_ui_import_page'),
49 'type' => MENU_LOCAL_TASK
50 );
51 $items['admin/build/views/tools'] = $base + array(
52 'title' => t('Tools'),
53 'page callback' => 'views_ui_admin_convert',
54 'type' => MENU_LOCAL_TASK
55 );
56 $items['admin/build/views/tools/convert'] = $base + array(
57 'title' => t('Convert'),
58 'description' => t('Convert stored Views 1 views.'),
59 'page callback' => 'views_ui_admin_convert',
60 'type' => MENU_DEFAULT_LOCAL_TASK,
61 'weight' => 1,
62 );
63 $items['admin/build/views/tools/other'] = $base + array(
64 'title' => t('Other'),
65 'page callback' => 'drupal_get_form',
66 'page arguments' => array('views_ui_admin_other'),
67 'type' => MENU_LOCAL_TASK,
68 'weight' => 2,
69 );
70 $items['admin/build/views1/delete'] = $callback + array(
71 'title' => t('Delete view'),
72 'page callback' => 'drupal_get_form',
73 'page arguments' => array('views_ui_delete1_confirm', 4),
74 );
75 $items['admin/build/views1/convert'] = $callback + array(
76 'title' => t('Convert view'),
77 'page callback' => 'views_ui_convert1',
78 'page arguments' => array(4),
79 );
80 $items['admin/build/views/delete/%views_ui_cache'] = $callback + array(
81 'title' => t('Delete view'),
82 'page callback' => 'drupal_get_form',
83 'page arguments' => array('views_ui_delete_confirm', 4),
84 );
85 $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
86 'page callback' => 'views_ui_enable_page',
87 'page arguments' => array(4),
88 );
89 $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
90 'page callback' => 'views_ui_disable_page',
91 'page arguments' => array(4),
92 );
93 $items['admin/build/views/export/%views_ui_cache'] = $callback + array(
94 'page callback' => 'drupal_get_form',
95 'page arguments' => array('views_ui_export_page', 4),
96 );
97 // lots of little edit form pieces.
98 $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array(
99 'page callback' => 'views_ui_edit_details',
100 'page arguments' => array(3, 5),
101 );
102 $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
103 'page callback' => 'views_ui_add_display',
104 'page arguments' => array(3, 5),
105 );
106 $items['admin/build/views/%views_ui_js/remove-display/%views_ui_cache'] = $callback + array(
107 'page callback' => 'views_ui_remove_display',
108 'page arguments' => array(3, 5),
109 );
110 $items['admin/build/views/%views_ui_js/rearrange/%views_ui_cache'] = $callback + array(
111 'page callback' => 'views_ui_rearrange_type',
112 'page arguments' => array(3, 5),
113 );
114 $items['admin/build/views/%views_ui_js/add-item/%views_ui_cache'] = $callback + array(
115 'page callback' => 'views_ui_add_item',
116 'page arguments' => array(3, 5),
117 );
118 $items['admin/build/views/%views_ui_js/config-item/%views_ui_cache'] = $callback + array(
119 'page callback' => 'views_ui_config_item',
120 'page arguments' => array(3, 5),
121 );
122 // display specific parameters
123 $items['admin/build/views/%views_ui_js/display/%views_ui_cache'] = $callback + array(
124 'page callback' => 'views_ui_edit_display',
125 'page arguments' => array(3, 5),
126 );
127 // Special style plugin stuff for arguments
128 $items['admin/build/views/%views_ui_js/change-style/%views_ui_cache'] = $callback + array(
129 'page callback' => 'views_ui_change_style',
130 'page arguments' => array(3, 5),
131 );
132 $items['admin/build/views/%views_ui_js/config-style/%views_ui_cache'] = $callback + array(
133 'page callback' => 'views_ui_config_style',
134 'page arguments' => array(3, 5),
135 );
136 // Live preview
137 $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
138 'page callback' => 'views_ui_preview',
139 'page arguments' => array(3, 5),
140 );
141 return $items;
142 }
143
144 function views_ui_help($path, $arg) {
145 switch ($path) {
146 case 'admin/build/views/tools':
147 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.') . '</p>';
148 }
149 }
150
151 /*
152 * Implementation of hook_perm()
153 */
154 function views_ui_perm() {
155 return array('administer views');
156 }
157
158 function views_ui_theme() {
159 $path = drupal_get_path('module', 'views');
160 include_once "$path/includes/admin.inc";
161
162 return array(
163 'views_ui_edit_view' => array(
164 'arguments' => array('view' => NULL),
165 'template' => 'views-ui-edit-view',
166 'path' => "$path/theme",
167 ),
168 'views_ui_edit_tab' => array(
169 'arguments' => array('view' => NULL, 'display' => NULL),
170 'template' => 'views-ui-edit-tab',
171 'path' => "$path/theme",
172 ),
173 'views_ui_edit_item' => array(
174 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL),
175 'template' => 'views-ui-edit-item',
176 'path' => "$path/theme",
177 ),
178 'views_ui_rearrange_form' => array(
179 'arguments' => array('form' => NULL),
180 'file' => '/includes/admin.inc',
181 ),
182 'views_tabset' => array(
183 'arguments' => array('tabs' => NULL),
184 'file' => '/includes/tabs.inc',
185 ),
186 'views_tab' => array(
187 'arguments' => array('body' => NULL),
188 'file' => '/includes/tabs.inc',
189 ),
190
191 'views_ui_style_plugin_table' => array(
192 'arguments' => array('form' => NULL),
193 ),
194
195 );
196 }
197
198 /**
199 * Specialized menu callback to load a view either out of the cache or just
200 * load it.
201 */
202 function views_ui_cache_load($name) {
203 views_include('cache');
204 views_include('view');
205 $view = views_object_cache_get('view', $name);
206
207 if (empty($view)) {
208 $v = views_get_view($name);
209 if ($v) {
210 $view = drupal_clone($v);
211 }
212 }
213
214 if (empty($view)) {
215 return FALSE;
216 }
217
218 else {
219 return $view;
220 }
221 }
222
223 /**
224 * Specialized menu callback to load a view that is only a default
225 * view.
226 */
227 function views_ui_default_load($name) {
228 $view = views_get_view($name);
229 if ($view->type == t('Default')) {
230 return $view;
231 }
232
233 return FALSE;
234 }
235
236 /**
237 * Check to see if the incoming menu item is js capable or not.
238 */
239 function views_ui_js_load($js) {
240 if ($js == 'ajax') {
241 return TRUE;
242 }
243 return 0;
244 }
245
246 /**
247 * Specialized cache function to add a flag to our view, include an appropriate
248 * include, and cache more easily.
249 */
250 function views_ui_cache_set($view) {
251 views_include('cache');
252 $view->changed = TRUE; // let any future object know that this view has changed.
253
254 // Unset handlers; we don't want to write these into the cache
255 unset($view->display_handler);
256 unset($view->current_display);
257 unset($view->default_display);
258 foreach (array_keys($view->display) as $id) {
259 unset($view->display[$id]->handler);
260 unset($view->display[$id]->default_display);
261 }
262 views_object_cache_set('view', $view->name, $view);
263 }