/[drupal]/contributions/modules/views/plugins/views_plugin_display_page.inc
ViewVC logotype

Contents of /contributions/modules/views/plugins/views_plugin_display_page.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Jun 26 00:23:42 2009 UTC (5 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.7: +3 -3 lines
File MIME type: text/x-php
#466454 by neclimdul: PHP strict fixes.
1 <?php
2 // $Id: views_plugin_display_page.inc,v 1.7 2009/06/02 20:37:15 merlinofchaos Exp $
3 /**
4 * @file
5 * Contains the page display plugin.
6 */
7
8 /**
9 * The plugin that handles a full page.
10 *
11 * @ingroup views_display_plugins
12 */
13 class views_plugin_display_page extends views_plugin_display {
14 /**
15 * The page display has a path.
16 */
17 function has_path() { return TRUE; }
18 function uses_breadcrumb() { return TRUE; }
19
20 function option_definition() {
21 $options = parent::option_definition();
22
23 $options['path'] = array('default' => '');
24 $options['menu'] = array(
25 'contains' => array(
26 'type' => array('default' => 'none'),
27 // Do not translate menu and title as menu system will.
28 'title' => array('default' => '', 'translatable' => FALSE),
29 'description' => array('default' => '', 'translatable' => FALSE),
30 'weight' => array('default' => 0),
31 'name' => array('default' => 'navigation'),
32 ),
33 );
34 $options['tab_options'] = array(
35 'contains' => array(
36 'type' => array('default' => 'none'),
37 // Do not translate menu and title as menu system will.
38 'title' => array('default' => '', 'translatable' => FALSE),
39 'description' => array('default' => '', 'translatable' => FALSE),
40 'weight' => array('default' => 0),
41 ),
42 );
43
44 return $options;
45 }
46
47 /**
48 * Add this display's path information to Drupal's menu system.
49 */
50 function execute_hook_menu() {
51 $items = array();
52 // Replace % with the link to our standard views argument loader
53 // views_arg_load -- which lives in views.module
54
55 $bits = explode('/', $this->get_option('path'));
56 $page_arguments = array($this->view->name, $this->display->id);
57
58 // Replace % with %views_arg for menu autoloading and add to the
59 // page arguments so the argument actually comes through.
60 foreach($bits as $pos => $bit) {
61 if ($bit == '%') {
62 $bits[$pos] = '%views_arg';
63 $page_arguments[] = $pos;
64 }
65 }
66
67 $path = implode('/', $bits);
68
69 $access_plugin = $this->get_access_plugin();
70
71 if ($path) {
72 $items[$path] = array(
73 // default views page entry
74 'page callback' => 'views_page',
75 'page arguments' => $page_arguments,
76 // Default access check (per display)
77 'access callback' => 'views_access',
78 'access arguments' => array($access_plugin->get_access_callback()),
79 // Identify URL embedded arguments and correlate them to a handler
80 'load arguments' => array($this->view->name, $this->display->id, '%index'),
81 );
82 $menu = $this->get_option('menu');
83 if (empty($menu)) {
84 $menu = array('type' => 'none');
85 }
86 // Set the title and description if we have one.
87 if ($menu['type'] != 'none') {
88 $items[$path]['title'] = $menu['title'];
89 $items[$path]['description'] = $menu['description'];
90 }
91
92 if (isset($menu['weight'])) {
93 $items[$path]['weight'] = intval($menu['weight']);
94 }
95
96 switch ($menu['type']) {
97 case 'none':
98 default:
99 $items[$path]['type'] = MENU_CALLBACK;
100 break;
101 case 'normal':
102 $items[$path]['type'] = MENU_NORMAL_ITEM;
103 // Insert item into the proper menu
104 $items[$path]['menu_name'] = $menu['name'];
105 break;
106 case 'tab':
107 $items[$path]['type'] = MENU_LOCAL_TASK;
108 break;
109 case 'default tab':
110 $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK;
111 break;
112 }
113
114 // If this is a 'default' tab, check to see if we have to create teh
115 // parent menu item.
116 if ($menu['type'] == 'default tab') {
117 $tab_options = $this->get_option('tab_options');
118 if (!empty($tab_options['type']) && $tab_options['type'] != 'none') {
119 $bits = explode('/', $path);
120 // Remove the last piece.
121 $bit = array_pop($bits);
122
123 // we can't do this if they tried to make the last path bit variable.
124 // @todo: We can validate this.
125 if ($bit != '%views_arg' && !empty($bits)) {
126 $default_path = implode('/', $bits);
127 $items[$default_path] = array(
128 // default views page entry
129 'page callback' => 'views_page',
130 'page arguments' => $page_arguments,
131 // Default access check (per display)
132 'access callback' => 'views_access',
133 'access arguments' => array($access_plugin->get_access_callback()),
134 // Identify URL embedded arguments and correlate them to a handler
135 'load arguments' => array($this->view->name, $this->display->id, '%index'),
136 'title' => $tab_options['title'],
137 'description' => $tab_options['description'],
138 );
139 switch ($tab_options['type']) {
140 default:
141 case 'normal':
142 $items[$default_path]['type'] = MENU_NORMAL_ITEM;
143 break;
144 case 'tab':
145 $items[$default_path]['type'] = MENU_LOCAL_TASK;
146 break;
147 }
148 if (isset($tab_options['weight'])) {
149 $items[$default_path]['weight'] = intval($tab_options['weight']);
150 }
151 }
152 }
153 }
154 }
155
156 return $items;
157 }
158
159 /**
160 * The display page handler returns a normal view, but it also does
161 * a drupal_set_title for the page, and does a views_set_page_view
162 * on the view.
163 */
164 function execute() {
165 // Let the world know that this is the page view we're using.
166 views_set_page_view($this);
167
168 // Prior to this being called, the $view should already be set to this
169 // display, and arguments should be set on the view.
170 $this->view->build();
171 if (!empty($this->view->build_info['fail'])) {
172 return drupal_not_found();
173 }
174
175 $this->view->get_breadcrumb(TRUE);
176
177 // And the title, which is much easier.
178 drupal_set_title(filter_xss_admin($this->view->get_title()));
179
180 // And now render the view.
181 return $this->view->render();
182 }
183
184 /**
185 * Provide the summary for page options in the views UI.
186 *
187 * This output is returned as an array.
188 */
189 function options_summary(&$categories, &$options) {
190 // It is very important to call the parent function here:
191 parent::options_summary($categories, $options);
192
193 $categories['page'] = array(
194 'title' => t('Page settings'),
195 );
196
197 $path = strip_tags($this->get_option('path'));
198 if (empty($path)) {
199 $path = t('None');
200 }
201
202 if (strlen($path) > 16) {
203 $path = substr($path, 0, 16) . '...';
204 }
205
206 $options['path'] = array(
207 'category' => 'page',
208 'title' => t('Path'),
209 'value' => $path,
210 );
211
212 $menu = $this->get_option('menu');
213 if (!is_array($menu)) {
214 $menu = array('type' => 'none');
215 }
216 switch($menu['type']) {
217 case 'none':
218 default:
219 $menu_str = t('No menu');
220 break;
221 case 'normal':
222 $menu_str = t('Normal: @title', array('@title' => $menu['title']));
223 break;
224 case 'tab':
225 case 'default tab':
226 $menu_str = t('Tab: @title', array('@title' => $menu['title']));
227 break;
228 }
229
230 if (strlen($menu_str) > 16) {
231 $menu_str = substr($menu_str, 0, 16) . '...';
232 }
233
234 $options['menu'] = array(
235 'category' => 'page',
236 'title' => t('Menu'),
237 'value' => $menu_str,
238 );
239
240 // This adds a 'Settings' link to the style_options setting if the style has options.
241 if ($menu['type'] == 'default tab') {
242 $options['menu']['links']['tab_options'] = t('Change settings for the parent menu');
243 }
244 }
245
246 /**
247 * Provide the default form for setting options.
248 */
249 function options_form(&$form, &$form_state) {
250 // It is very important to call the parent function here:
251 parent::options_form($form, $form_state);
252
253 switch ($form_state['section']) {
254 case 'path':
255 $form['#title'] .= t('The menu path or URL of this view');
256 $form['#help_topic'] = 'path';
257 $form['path'] = array(
258 '#type' => 'textfield',
259 '#description' => t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for arguments: For example, "node/%/feed".'),
260 '#default_value' => $this->get_option('path'),
261 '#field_prefix' => '<span dir="ltr">' . url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
262 '#field_suffix' => '</span>&lrm;',
263 '#attributes' => array('dir'=>'ltr'),
264 );
265 break;
266 case 'menu':
267 $form['#title'] .= t('Menu item entry');
268 $form['#help_topic'] = 'menu';
269 $form['menu'] = array(
270 '#prefix' => '<div class="clear-block">',
271 '#suffix' => '</div>',
272 '#tree' => TRUE,
273 );
274 $menu = $this->get_option('menu');
275 if (empty($menu)) {
276 $menu = array('type' => 'none', 'title' => '', 'weight' => 0);
277 }
278 $form['menu']['type'] = array(
279 '#prefix' => '<div class="views-left-30">',
280 '#suffix' => '</div>',
281 '#title' => t('Type'),
282 '#type' => 'radios',
283 '#options' => array(
284 'none' => t('No menu entry'),
285 'normal' => t('Normal menu entry'),
286 'tab' => t('Menu tab'),
287 'default tab' => t('Default menu tab')
288 ),
289 '#default_value' => $menu['type'],
290 );
291 $form['menu']['title'] = array(
292 '#prefix' => '<div class="views-left-50">',
293 '#title' => t('Title'),
294 '#type' => 'textfield',
295 '#default_value' => $menu['title'],
296 '#description' => t('If set to normal or tab, enter the text to use for the menu item.'),
297 '#process' => array('views_process_dependency'),
298 '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
299 );
300 $form['menu']['description'] = array(
301 '#title' => t('Description'),
302 '#type' => 'textfield',
303 '#default_value' => $menu['description'],
304 '#description' => t("If set to normal or tab, enter the text to use for the menu item's description."),
305 '#process' => array('views_process_dependency'),
306 '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
307 );
308 $form['menu']['name-warning'] = array(
309 '#type' => 'markup',
310 '#prefix' => '<div class="warning">',
311 '#value' => t("Warning: Changing this item's menu will not work reliably in Drupal 6.4 or earlier. Please upgrade your copy of Drupal at !url.", array('!url' => l('drupal.org', 'http://drupal.org/project/Drupal+project'))),
312 '#suffix' => '</div>',
313 '#process' => array('views_process_dependency'),
314 '#dependency' => array('radio:menu[type]' => array('normal')),
315 '#access' => version_compare(VERSION, '6.5', '<'),
316 );
317
318 // Only display the menu selector if menu module is enabled.
319 if (module_exists('menu')) {
320 $form['menu']['name'] = array(
321 '#title' => t('Menu'),
322 '#type' => 'select',
323 '#options' => menu_get_menus(),
324 '#default_value' => $menu['name'],
325 '#description' => t('Insert item into an available menu.'), //
326 '#process' => array('views_process_dependency'),
327 '#dependency' => array('radio:menu[type]' => array('normal')),
328 );
329 }
330 else {
331 $form['menu']['name'] = array(
332 '#type' => 'value',
333 '#value' => $menu['name'],
334 );
335 $form['menu']['markup'] = array(
336 '#value' => t('Menu selection requires the activation of menu module.'),
337 );
338 }
339 $form['menu']['weight'] = array(
340 '#suffix' => '</div>',
341 '#title' => t('Weight'),
342 '#type' => 'textfield',
343 '#default_value' => isset($menu['weight']) ? $menu['weight'] : 0,
344 '#description' => t('The lower the weight the higher/further left it will appear.'),
345 '#process' => array('views_process_dependency'),
346 '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
347 );
348 break;
349 case 'tab_options':
350 $form['#title'] .= t('Default tab options');
351 $tab_options = $this->get_option('tab_options');
352 if (empty($tab_options)) {
353 $tab_options = array('type' => 'none', 'title' => '', 'weight' => 0);
354 }
355
356 $form['tab_markup'] = array(
357 '#prefix' => '<div class="form-item description">',
358 '#suffix' => '</div>',
359 '#value' => t('When providing a menu item as a tab, Drupal needs to know what the parent menu item of that tab will be. Sometimes the parent will already exist, but other times you will need to have one created. The path of a parent item will always be the same path with the last part left off. i.e, if the path to this view is <em>foo/bar/baz</em>, the parent path would be <em>foo/bar</em>.'),
360 );
361
362 $form['tab_options'] = array(
363 '#prefix' => '<div class="clear-block">',
364 '#suffix' => '</div>',
365 '#tree' => TRUE,
366 );
367 $form['tab_options']['type'] = array(
368 '#prefix' => '<div class="views-left-25">',
369 '#suffix' => '</div>',
370 '#title' => t('Parent menu item'),
371 '#type' => 'radios',
372 '#options' => array('none' => t('Already exists'), 'normal' => t('Normal menu item'), 'tab' => t('Menu tab')),
373 '#default_value' => $tab_options['type'],
374 );
375 $form['tab_options']['title'] = array(
376 '#prefix' => '<div class="views-left-75">',
377 '#title' => t('Title'),
378 '#type' => 'textfield',
379 '#default_value' => $tab_options['title'],
380 '#description' => t('If creating a parent menu item, enter the title of the item.'),
381 '#process' => array('views_process_dependency'),
382 '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')),
383 );
384 $form['tab_options']['description'] = array(
385 '#title' => t('Description'),
386 '#type' => 'textfield',
387 '#default_value' => $tab_options['description'],
388 '#description' => t('If creating a parent menu item, enter the description of the item.'),
389 '#process' => array('views_process_dependency'),
390 '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')),
391 );
392 $form['tab_options']['weight'] = array(
393 '#suffix' => '</div>',
394 '#title' => t('Tab weight'),
395 '#type' => 'textfield',
396 '#default_value' => $tab_options['weight'],
397 '#size' => 5,
398 '#description' => t('If the parent menu item is a tab, enter the weight of the tab. The lower the number, the more to the left it will be.'),
399 '#process' => array('views_process_dependency'),
400 '#dependency' => array('radio:tab_options[type]' => array('tab')),
401 );
402 break;
403 }
404 }
405
406 function options_validate(&$form, &$form_state) {
407 // It is very important to call the parent function here:
408 parent::options_validate($form, $form_state);
409 switch ($form_state['section']) {
410 case 'path':
411 if (strpos($form_state['values']['path'], '$arg') !== FALSE) {
412 form_error($form['path'], t('"$arg" is no longer supported. Use % instead.'));
413 }
414
415 if (strpos($form_state['values']['path'], '%') === 0) {
416 form_error($form['path'], t('"%" may not be used for the first segment of a path.'));
417 }
418
419 // automatically remove '/' from path.
420 $form_state['values']['path'] = trim($form_state['values']['path'], '/');
421
422 break;
423 case 'menu':
424 $path = $this->get_option('path');
425 if ($form_state['values']['menu']['type'] == 'normal' && strpos($path, '%') !== FALSE) {
426 form_error($form['menu']['type'], t('Views cannot create normal menu items for paths with a % in them.'));
427 }
428
429 if ($form_state['values']['menu']['type'] == 'default tab' || $form_state['values']['menu']['type'] == 'tab') {
430 $bits = explode('/', $path);
431 $last = array_pop($bits);
432 if ($last == '%') {
433 form_error($form['menu']['type'], t('A display whose path ends with a % cannot be a tab.'));
434 }
435 }
436
437 if ($form_state['values']['menu']['type'] != 'none' && empty($form_state['values']['menu']['title'])) {
438 form_error($form['menu']['title'], t('Title is required for this menu type.'));
439 }
440 break;
441 }
442 }
443
444 function options_submit(&$form, &$form_state) {
445 // It is very important to call the parent function here:
446 parent::options_submit($form, $form_state);
447 switch ($form_state['section']) {
448 case 'path':
449 $this->set_option('path', $form_state['values']['path']);
450 break;
451 case 'menu':
452 $this->set_option('menu', $form_state['values']['menu']);
453 // send ajax form to options page if we use it.
454 if ($form_state['values']['menu']['type'] == 'default tab') {
455 views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('tab_options'));
456 }
457 break;
458 case 'tab_options':
459 $this->set_option('tab_options', $form_state['values']['tab_options']);
460 break;
461 }
462 }
463
464 function validate() {
465 $errors = parent::validate();
466
467 $menu = $this->get_option('menu');
468 if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) {
469 $errors[] = t('Display @display is set to use a menu but the menu title is not set.', array('@display' => $this->display->display_title));
470 }
471
472 if ($menu['type'] == 'default tab') {
473 $tab_options = $this->get_option('tab_options');
474 if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) {
475 $errors[] = t('Display @display is set to use a parent menu but the parent menu title is not set.', array('@display' => $this->display->display_title));
476 }
477 }
478
479 return $errors;
480 }
481 }

  ViewVC Help
Powered by ViewVC 1.1.2