• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

plugins/views_plugin_display_page.inc

Go to the documentation of this file.
00001 <?php
00012 class views_plugin_display_page extends views_plugin_display {
00016   function has_path() { return TRUE; }
00017   function uses_breadcrumb() { return TRUE; }
00018 
00019   function option_definition() {
00020     $options = parent::option_definition();
00021 
00022     $options['path'] = array('default' => '');
00023     $options['menu'] = array(
00024       'contains' => array(
00025         'type' => array('default' => 'none'),
00026         // Do not translate menu and title as menu system will.
00027         'title' => array('default' => '', 'translatable' => FALSE),
00028         'description' => array('default' => '', 'translatable' => FALSE),
00029         'weight' => array('default' => 0),
00030         'name' => array('default' => variable_get('menu_default_node_menu', 'navigation')),
00031         'context' => array('default' => ''),
00032        ),
00033     );
00034     $options['tab_options'] = array(
00035       'contains' => array(
00036         'type' => array('default' => 'none'),
00037         // Do not translate menu and title as menu system will.
00038         'title' => array('default' => '', 'translatable' => FALSE),
00039         'description' => array('default' => '', 'translatable' => FALSE),
00040         'weight' => array('default' => 0),
00041         'name' => array('default' => 'navigation'),
00042        ),
00043     );
00044 
00045     return $options;
00046   }
00047 
00051   function execute_hook_menu($callbacks) {
00052     $items = array();
00053     // Replace % with the link to our standard views argument loader
00054     // views_arg_load -- which lives in views.module
00055 
00056     $bits = explode('/', $this->get_option('path'));
00057     $page_arguments = array($this->view->name, $this->display->id);
00058     $this->view->init_handlers();
00059     $view_arguments = $this->view->argument;
00060 
00061     // Replace % with %views_arg for menu autoloading and add to the
00062     // page arguments so the argument actually comes through.
00063     foreach ($bits as $pos => $bit) {
00064       if ($bit == '%') {
00065         $argument = array_shift($view_arguments);
00066         if (!empty($argument->options['specify_validation']) && $argument->options['validate']['type'] != 'none') {
00067           $bits[$pos] = '%views_arg';
00068         }
00069         $page_arguments[] = $pos;
00070       }
00071     }
00072 
00073     $path = implode('/', $bits);
00074 
00075     $access_plugin = $this->get_plugin('access');
00076     if (!isset($access_plugin)) {
00077       $access_plugin = views_get_plugin('access', 'none');
00078     }
00079 
00080     // Get access callback might return an array of the callback + the dynamic arguments.
00081     $access_plugin_callback = $access_plugin->get_access_callback();
00082 
00083     if (is_array($access_plugin_callback)) {
00084       $access_arguments = array();
00085 
00086       // Find the plugin arguments.
00087       $access_plugin_method = array_shift($access_plugin_callback);
00088       $access_plugin_arguments = array_shift($access_plugin_callback);
00089       if (!is_array($access_plugin_arguments)) {
00090         $access_plugin_arguments = array();
00091       }
00092 
00093       $access_arguments[0] = array($access_plugin_method, &$access_plugin_arguments);
00094 
00095       // Move the plugin arguments to the access arguments array.
00096       $i = 1;
00097       foreach ($access_plugin_arguments as $key => $value) {
00098         if (is_int($value)) {
00099           $access_arguments[$i] = $value;
00100           $access_plugin_arguments[$key] = $i;
00101           $i++;
00102         }
00103       }
00104     }
00105     else {
00106       $access_arguments = array($access_plugin_callback);
00107     }
00108 
00109     if ($path) {
00110       $items[$path] = array(
00111         // default views page entry
00112         'page callback' => 'views_page',
00113         'page arguments' => $page_arguments,
00114         // Default access check (per display)
00115         'access callback' => 'views_access',
00116         'access arguments' => $access_arguments,
00117         // Identify URL embedded arguments and correlate them to a handler
00118         'load arguments'  => array($this->view->name, $this->display->id, '%index'),
00119       );
00120       $menu = $this->get_option('menu');
00121       if (empty($menu)) {
00122         $menu = array('type' => 'none');
00123       }
00124       // Set the title and description if we have one.
00125       if ($menu['type'] != 'none') {
00126         $items[$path]['title'] = $menu['title'];
00127         $items[$path]['description'] = $menu['description'];
00128       }
00129 
00130       if (isset($menu['weight'])) {
00131         $items[$path]['weight'] = intval($menu['weight']);
00132       }
00133 
00134       switch ($menu['type']) {
00135         case 'none':
00136         default:
00137           $items[$path]['type'] = MENU_CALLBACK;
00138           break;
00139         case 'normal':
00140           $items[$path]['type'] = MENU_NORMAL_ITEM;
00141           // Insert item into the proper menu
00142           $items[$path]['menu_name'] = $menu['name'];
00143           break;
00144         case 'tab':
00145           $items[$path]['type'] = MENU_LOCAL_TASK;
00146           break;
00147         case 'default tab':
00148           $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK;
00149           break;
00150       }
00151 
00152       // Add context for contextual links.
00153       // @see menu_contextual_links()
00154       if (!empty($menu['context'])) {
00155         $items[$path]['context'] = MENU_CONTEXT_INLINE;
00156       }
00157 
00158       // If this is a 'default' tab, check to see if we have to create teh
00159       // parent menu item.
00160       if ($menu['type'] == 'default tab') {
00161         $tab_options = $this->get_option('tab_options');
00162         if (!empty($tab_options['type']) && $tab_options['type'] != 'none') {
00163           $bits = explode('/', $path);
00164           // Remove the last piece.
00165           $bit = array_pop($bits);
00166 
00167           // we can't do this if they tried to make the last path bit variable.
00168           // @todo: We can validate this.
00169           if ($bit != '%views_arg' && !empty($bits)) {
00170             $default_path = implode('/', $bits);
00171             $items[$default_path] = array(
00172               // default views page entry
00173               'page callback' => 'views_page',
00174               'page arguments' => $page_arguments,
00175               // Default access check (per display)
00176               'access callback' => 'views_access',
00177               'access arguments' => $access_arguments,
00178               // Identify URL embedded arguments and correlate them to a handler
00179               'load arguments'  => array($this->view->name, $this->display->id, '%index'),
00180               'title' => $tab_options['title'],
00181               'description' => $tab_options['description'],
00182               'menu_name' => $tab_options['name'],
00183             );
00184             switch ($tab_options['type']) {
00185               default:
00186               case 'normal':
00187                 $items[$default_path]['type'] = MENU_NORMAL_ITEM;
00188                 break;
00189               case 'tab':
00190                 $items[$default_path]['type'] = MENU_LOCAL_TASK;
00191                 break;
00192             }
00193             if (isset($tab_options['weight'])) {
00194               $items[$default_path]['weight'] = intval($tab_options['weight']);
00195             }
00196           }
00197         }
00198       }
00199     }
00200 
00201     return $items;
00202   }
00203 
00209   function execute() {
00210     // Let the world know that this is the page view we're using.
00211     views_set_page_view($this->view);
00212 
00213     // Prior to this being called, the $view should already be set to this
00214     // display, and arguments should be set on the view.
00215     $this->view->build();
00216     if (!empty($this->view->build_info['fail'])) {
00217       return drupal_not_found();
00218     }
00219 
00220     $this->view->get_breadcrumb(TRUE);
00221 
00222 
00223     // And now render the view.
00224     $render = $this->view->render();
00225 
00226     // First execute the view so it's possible to get tokens for the title.
00227     // And the title, which is much easier.
00228     drupal_set_title(filter_xss_admin($this->view->get_title()), PASS_THROUGH);
00229     return $render;
00230   }
00231 
00237   function options_summary(&$categories, &$options) {
00238     // It is very important to call the parent function here:
00239     parent::options_summary($categories, $options);
00240 
00241     $categories['page'] = array(
00242       'title' => t('Page settings'),
00243       'column' => 'second',
00244       'build' => array(
00245         '#weight' => -10,
00246       ),
00247     );
00248 
00249     $path = strip_tags('/' . $this->get_option('path'));
00250     if (empty($path)) {
00251       $path = t('None');
00252     }
00253 
00254     $options['path'] = array(
00255       'category' => 'page',
00256       'title' => t('Path'),
00257       'value' => views_ui_truncate($path, 24),
00258     );
00259 
00260     $menu = $this->get_option('menu');
00261     if (!is_array($menu)) {
00262       $menu = array('type' => 'none');
00263     }
00264     switch($menu['type']) {
00265       case 'none':
00266       default:
00267         $menu_str = t('No menu');
00268         break;
00269       case 'normal':
00270         $menu_str = t('Normal: @title', array('@title' => $menu['title']));
00271         break;
00272       case 'tab':
00273       case 'default tab':
00274         $menu_str = t('Tab: @title', array('@title' => $menu['title']));
00275         break;
00276     }
00277 
00278     $options['menu'] = array(
00279       'category' => 'page',
00280       'title' => t('Menu'),
00281       'value' => views_ui_truncate($menu_str, 24),
00282     );
00283 
00284     // This adds a 'Settings' link to the style_options setting if the style has options.
00285     if ($menu['type'] == 'default tab') {
00286       $options['menu']['setting'] = t('Parent menu item');
00287       $options['menu']['links']['tab_options'] = t('Change settings for the parent menu');
00288     }
00289   }
00290 
00294   function options_form(&$form, &$form_state) {
00295     parent::options_form($form, $form_state);
00296     // It is very important to call the parent function here:
00297     parent::options_form($form, $form_state);
00298 
00299     switch ($form_state['section']) {
00300       case 'path':
00301         $form['#title'] .= t('The menu path or URL of this view');
00302         $form['#help_topic'] = 'path';
00303         $form['path'] = array(
00304           '#type' => 'textfield',
00305           '#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 contextual filters: For example, "node/%/feed".'),
00306           '#default_value' => $this->get_option('path'),
00307     '#field_prefix' => '<span dir="ltr">' . url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
00308     '#field_suffix' => '</span>&lrm;',
00309     '#attributes' => array('dir'=>'ltr'),
00310         );
00311         break;
00312       case 'menu':
00313         $form['#title'] .= t('Menu item entry');
00314         $form['#help_topic'] = 'menu';
00315         $form['menu'] = array(
00316           '#prefix' => '<div class="clearfix">',
00317           '#suffix' => '</div>',
00318           '#tree' => TRUE,
00319         );
00320         $menu = $this->get_option('menu');
00321         if (empty($menu)) {
00322           $menu = array('type' => 'none', 'title' => '', 'weight' => 0);
00323         }
00324         $form['menu']['type'] = array(
00325           '#prefix' => '<div class="views-left-30">',
00326           '#suffix' => '</div>',
00327           '#title' => t('Type'),
00328           '#type' => 'radios',
00329           '#options' => array(
00330             'none' => t('No menu entry'),
00331             'normal' => t('Normal menu entry'),
00332             'tab' => t('Menu tab'),
00333             'default tab' => t('Default menu tab')
00334           ),
00335           '#default_value' => $menu['type'],
00336         );
00337         $form['menu']['title'] = array(
00338           '#prefix' => '<div class="views-left-50">',
00339           '#title' => t('Title'),
00340           '#type' => 'textfield',
00341           '#default_value' => $menu['title'],
00342           '#description' => t('If set to normal or tab, enter the text to use for the menu item.'),
00343           '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
00344         );
00345         $form['menu']['description'] = array(
00346           '#title' => t('Description'),
00347           '#type' => 'textfield',
00348           '#default_value' => $menu['description'],
00349           '#description' => t("If set to normal or tab, enter the text to use for the menu item's description."),
00350           '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
00351         );
00352 
00353         // Only display the menu selector if menu module is enabled.
00354         if (module_exists('menu')) {
00355           $form['menu']['name'] = array(
00356             '#title' => t('Menu'),
00357             '#type' => 'select',
00358             '#options' => menu_get_menus(),
00359             '#default_value' => $menu['name'],
00360             '#description' => t('Insert item into an available menu.'),
00361             '#dependency' => array('radio:menu[type]' => array('normal', 'tab')),
00362           );
00363         }
00364         else {
00365           $form['menu']['name'] = array(
00366             '#type' => 'value',
00367             '#value' => $menu['name'],
00368           );
00369           $form['menu']['markup'] = array(
00370             '#markup' => t('Menu selection requires the activation of menu module.'),
00371           );
00372         }
00373         $form['menu']['weight'] = array(
00374           '#suffix' => '</div>',
00375           '#title' => t('Weight'),
00376           '#type' => 'textfield',
00377           '#default_value' => isset($menu['weight']) ? $menu['weight'] : 0,
00378           '#description' => t('The lower the weight the higher/further left it will appear.'),
00379           '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')),
00380         );
00381         $form['menu']['context'] = array(
00382           '#title' => t('Context'),
00383           '#type' => 'checkbox',
00384           '#default_value' => !empty($menu['context']),
00385           '#description' => t('Displays the link in contextual links'),
00386           '#dependency' => array('radio:menu[type]' => array('tab')),
00387         );
00388         break;
00389       case 'tab_options':
00390         $form['#title'] .= t('Default tab options');
00391         $tab_options = $this->get_option('tab_options');
00392         if (empty($tab_options)) {
00393           $tab_options = array('type' => 'none', 'title' => '', 'weight' => 0);
00394         }
00395 
00396         $form['tab_markup'] = array(
00397           '#markup' => '<div class="form-item description">' . 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>.') . '</div>',
00398         );
00399 
00400         $form['tab_options'] = array(
00401           '#prefix' => '<div class="clearfix">',
00402           '#suffix' => '</div>',
00403           '#tree' => TRUE,
00404         );
00405         $form['tab_options']['type'] = array(
00406           '#prefix' => '<div class="views-left-25">',
00407           '#suffix' => '</div>',
00408           '#title' => t('Parent menu item'),
00409           '#type' => 'radios',
00410           '#options' => array('none' => t('Already exists'), 'normal' => t('Normal menu item'), 'tab' => t('Menu tab')),
00411           '#default_value' => $tab_options['type'],
00412         );
00413         $form['tab_options']['title'] = array(
00414           '#prefix' => '<div class="views-left-75">',
00415           '#title' => t('Title'),
00416           '#type' => 'textfield',
00417           '#default_value' => $tab_options['title'],
00418           '#description' => t('If creating a parent menu item, enter the title of the item.'),
00419           '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')),
00420         );
00421         $form['tab_options']['description'] = array(
00422           '#title' => t('Description'),
00423           '#type' => 'textfield',
00424           '#default_value' => $tab_options['description'],
00425           '#description' => t('If creating a parent menu item, enter the description of the item.'),
00426           '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')),
00427         );
00428         // Only display the menu selector if menu module is enabled.
00429         if (module_exists('menu')) {
00430           $form['tab_options']['name'] = array(
00431             '#title' => t('Menu'),
00432             '#type' => 'select',
00433             '#options' => menu_get_menus(),
00434             '#default_value' => $tab_options['name'],
00435             '#description' => t('Insert item into an available menu.'),
00436             '#dependency' => array('radio:tab_options[type]' => array('normal')),
00437           );
00438         }
00439         else {
00440           $form['tab_options']['name'] = array(
00441             '#type' => 'value',
00442             '#value' => $tab_options['name'],
00443           );
00444           $form['tab_options']['markup'] = array(
00445             '#markup' => t('Menu selection requires the activation of menu module.'),
00446           );
00447         }
00448         $form['tab_options']['weight'] = array(
00449           '#suffix' => '</div>',
00450           '#title' => t('Tab weight'),
00451           '#type' => 'textfield',
00452           '#default_value' => $tab_options['weight'],
00453           '#size' => 5,
00454           '#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.'),
00455           '#dependency' => array('radio:tab_options[type]' => array('tab')),
00456         );
00457         break;
00458     }
00459   }
00460 
00461   function options_validate(&$form, &$form_state) {
00462     // It is very important to call the parent function here:
00463     parent::options_validate($form, $form_state);
00464     switch ($form_state['section']) {
00465       case 'path':
00466         if (strpos($form_state['values']['path'], '$arg') !== FALSE) {
00467           form_error($form['path'], t('"$arg" is no longer supported. Use % instead.'));
00468         }
00469 
00470         if (strpos($form_state['values']['path'], '%') === 0) {
00471           form_error($form['path'], t('"%" may not be used for the first segment of a path.'));
00472         }
00473 
00474         // automatically remove '/' from path.
00475         $form_state['values']['path'] = trim($form_state['values']['path'], '/');
00476 
00477         break;
00478       case 'menu':
00479         $path = $this->get_option('path');
00480         if ($form_state['values']['menu']['type'] == 'normal' && strpos($path, '%') !== FALSE) {
00481           form_error($form['menu']['type'], t('Views cannot create normal menu items for paths with a % in them.'));
00482         }
00483 
00484         if ($form_state['values']['menu']['type'] == 'default tab' || $form_state['values']['menu']['type'] == 'tab') {
00485           $bits = explode('/', $path);
00486           $last = array_pop($bits);
00487           if ($last == '%') {
00488             form_error($form['menu']['type'], t('A display whose path ends with a % cannot be a tab.'));
00489           }
00490         }
00491 
00492         if ($form_state['values']['menu']['type'] != 'none' && empty($form_state['values']['menu']['title'])) {
00493           form_error($form['menu']['title'], t('Title is required for this menu type.'));
00494         }
00495         break;
00496     }
00497   }
00498 
00499   function options_submit(&$form, &$form_state) {
00500     // It is very important to call the parent function here:
00501     parent::options_submit($form, $form_state);
00502     switch ($form_state['section']) {
00503       case 'path':
00504         $this->set_option('path', $form_state['values']['path']);
00505         break;
00506       case 'menu':
00507         $this->set_option('menu', $form_state['values']['menu']);
00508         // send ajax form to options page if we use it.
00509         if ($form_state['values']['menu']['type'] == 'default tab') {
00510           views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('tab_options'));
00511         }
00512         break;
00513       case 'tab_options':
00514         $this->set_option('tab_options', $form_state['values']['tab_options']);
00515         break;
00516     }
00517   }
00518 
00519   function validate() {
00520     $errors = parent::validate();
00521 
00522     $menu = $this->get_option('menu');
00523     if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) {
00524       $errors[] = t('Display @display is set to use a menu but the menu link text is not set.', array('@display' => $this->display->display_title));
00525     }
00526 
00527     if ($menu['type'] == 'default tab') {
00528       $tab_options = $this->get_option('tab_options');
00529       if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) {
00530         $errors[] = t('Display @display is set to use a parent menu but the parent menu link text is not set.', array('@display' => $this->display->display_title));
00531       }
00532     }
00533 
00534     return $errors;
00535   }
00536 
00537   function get_argument_text() {
00538     return array(
00539       'filter value not present' => t('When the filter value is <em>NOT</em> in the URL'),
00540       'filter value present' => t('When the filter value <em>IS</em> in the URL or a default is provided'),
00541       'description' => t('The contextual filter values is provided by the URL.'),
00542     );
00543   }
00544 
00545   function get_pager_text() {
00546     return array(
00547       'items per page title' => t('Items per page'),
00548       'items per page description' => t('The number of items to display per page. Enter 0 for no limit.')
00549     );
00550   }
00551 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1