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