source: sipei/modules/views/plugins/views_plugin_display_page.inc

drupal-6.x
Last change on this file was ffa4103, checked in by Luis Peña <lpena@…>, 12 años ago

Cambiando el nombre de modulos a modules

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