| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: term_view.inc,v 1.5.2.1 2010/06/22 14:48:38 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Handle the 'term view' override task. 7 * 8 * This plugin overrides term/%term and reroutes it to the page manager, where 9 * a list of tasks can be used to service this request based upon criteria 10 * supplied by access plugins. 11 */ 12 13 /** 14 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for 15 * more information. 16 */ 17 function page_manager_term_view_page_manager_tasks() { 18 if (module_exists('taxonomy')) { 19 return array( 20 // This is a 'page' task and will fall under the page admin UI 21 'task type' => 'page', 22 23 'title' => t('Taxonomy term template'), 24 'admin title' => t('Taxonomy term template'), 25 'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying taxonomy terms at <em>taxonomy/term/%term</em>. If you add variants, you may use selection criteria such as vocabulary or user access to provide different displays of the taxonomy term and associated nodes. If no variant is selected, the default Drupal taxonomy term display will be used. This page only affects items actually displayed ad taxonomy/term/%term. Some taxonomy terms, such as forums, have their displays moved elsewhere. Also please note that if you are using pathauto, aliases may make a taxonomy terms appear somewhere else, but as far as Drupal is concerned, they are still at taxonomy/term/%term.'), 26 'admin path' => 'taxonomy/term/%term', 27 'admin summary' => 'page_manager_term_view_admin_summary', 28 29 // Menu hooks so that we can alter the term/%term menu entry to point to us. 30 'hook menu' => 'page_manager_term_view_menu', 31 'hook menu alter' => 'page_manager_term_view_menu_alter', 32 33 // Provide a setting to the primary settings UI for Panels 34 'admin settings' => 'page_manager_term_view_admin_settings', 35 // Even though we don't have subtasks, this allows us to save our settings. 36 'save subtask callback' => 'page_manager_term_view_save', 37 38 // Callback to add items to the page manager task administration form: 39 'task admin' => 'page_manager_term_view_task_admin', 40 41 // This is task uses 'context' handlers and must implement these to give the 42 // handler data it needs. 43 'handler type' => 'context', 44 'get arguments' => 'page_manager_term_view_get_arguments', 45 'get context placeholders' => 'page_manager_term_view_get_contexts', 46 47 // Allow this to be enabled or disabled: 48 'disabled' => variable_get('page_manager_term_view_disabled', TRUE), 49 'enable callback' => 'page_manager_term_view_enable', 50 51 // Allow additional operations 52 'operations' => array( 53 'settings' => array( 54 'title' => t('Settings'), 55 'description' => t('Edit name, path and other basic settings for the page.'), 56 'form' => 'page_manager_term_view_settings', 57 ), 58 ), 59 ); 60 } 61 } 62 63 /** 64 * Callback defined by page_manager_term_view_page_manager_tasks(). 65 * 66 * Alter the term view input so that term view comes to us rather than the 67 * normal term view process. 68 */ 69 function page_manager_term_view_menu_alter(&$items, $task) { 70 if (variable_get('page_manager_term_view_disabled', TRUE)) { 71 return; 72 } 73 74 // Override the term view handler for our purpose, but only if someone else 75 // has not already done so. 76 if (isset($items['taxonomy/term/%']) && $items['taxonomy/term/%']['page callback'] == 'taxonomy_term_page' || variable_get('page_manager_override_anyway', FALSE)) { 77 $items['taxonomy/term/%']['page callback'] = 'page_manager_term_view'; 78 $items['taxonomy/term/%']['file path'] = $task['path']; 79 $items['taxonomy/term/%']['file'] = $task['file']; 80 } 81 else { 82 // automatically disable this task if it cannot be enabled. 83 variable_set('page_manager_term_view_disabled', TRUE); 84 if (!empty($GLOBALS['page_manager_enabling_term_view'])) { 85 drupal_set_message(t('Page manager module is unable to enable taxonomy/term/%term because some other module already has overridden with %callback.', array('%callback' => $items['taxonomy/term/%']['page callback'])), 'error'); 86 } 87 } 88 } 89 90 /** 91 * Entry point for our overridden term view. 92 * 93 * This function asks its assigned handlers who, if anyone, would like 94 * to run with it. If no one does, it passes through to Drupal core's 95 * term view, which is term_page_view(). 96 */ 97 function page_manager_term_view($terms, $depth = 0, $op = 'page') { 98 // While we ordinarily should never actually get feeds through here, 99 // just in case 100 if ($op != 'feed') { 101 // Load my task plugin 102 $task = page_manager_get_task('term_view'); 103 104 // Load the term into a context. 105 ctools_include('context'); 106 ctools_include('context-task-handler'); 107 $contexts = ctools_context_handler_get_task_contexts($task, '', array($terms, $depth)); 108 109 if (empty($contexts)) { 110 return drupal_not_found(); 111 } 112 113 // Add a fake tab for 'View' so that edit tabs can be added. 114 if (user_access('administer page manager')) { 115 ctools_include('menu'); 116 ctools_menu_add_tab(array( 117 'title' => t('View'), 118 'href' => $_GET['q'], 119 'type' => MENU_DEFAULT_LOCAL_TASK, 120 'weight' => -10, 121 )); 122 } 123 124 $output = ctools_context_handler_render($task, '', $contexts, array($terms, $depth, $op)); 125 if ($output !== FALSE) { 126 return $output; 127 } 128 } 129 130 // Otherwise, fall back. 131 module_load_include('inc', 'taxonomy', 'taxonomy.pages'); 132 return taxonomy_term_page($terms, $depth, $op); 133 } 134 135 /** 136 * Callback to get arguments provided by this task handler. 137 * 138 * Since this is the term view and there is no UI on the arguments, we 139 * create dummy arguments that contain the needed data. 140 */ 141 function page_manager_term_view_get_arguments($task, $subtask_id) { 142 return array( 143 array( 144 'keyword' => 'term', 145 'identifier' => variable_get('page_manager_term_view_type', 'multiple') == 'multiple' ? t('Term(s) being viewed') : t('Term being viewed'), 146 'id' => 1, 147 'name' => variable_get('page_manager_term_view_type', 'multiple') == 'multiple' ? 'terms' : 'term', 148 'settings' => array('input_form' => 'tid', 'breadcrumb' => variable_get('page_manager_taxonomy_breadcrumb', TRUE)), 149 'default' => '404', 150 ), 151 array( 152 'keyword' => 'depth', 153 'identifier' => t('Depth'), 154 'id' => 1, 155 'name' => 'string', 156 'settings' => array(), 157 ), 158 ); 159 } 160 161 /** 162 * Callback to get context placeholders provided by this handler. 163 */ 164 function page_manager_term_view_get_contexts($task, $subtask_id) { 165 return ctools_context_get_placeholders_from_argument(page_manager_term_view_get_arguments($task, $subtask_id)); 166 } 167 168 /** 169 * Settings page for this item. 170 */ 171 function page_manager_term_view_settings(&$form, &$form_state) { 172 // This passes thru because the setting can also appear on the main Panels 173 // settings form. If $settings is an array it will just pick up the default. 174 $settings = isset($form_state->update_values) ? $form_state->update_values : array(); 175 page_manager_term_view_admin_settings($form, $settings); 176 } 177 178 /** 179 * Copy form values into the page cache. 180 */ 181 function page_manager_term_view_settings_submit(&$form, &$form_state) { 182 $form_state['page']->update_values = $form_state['values']; 183 } 184 185 /** 186 * Save when the page cache is saved. 187 */ 188 function page_manager_term_view_save($subtask, $cache) { 189 if (isset($cache->update_values)) { 190 variable_set('page_manager_term_view_type', $cache->update_values['page_manager_term_view_type']); 191 variable_set('page_manager_taxonomy_breadcrumb', $cache->update_values['page_manager_taxonomy_breadcrumb']); 192 } 193 } 194 195 /** 196 * Provide a setting to the Panels administrative form. 197 */ 198 function page_manager_term_view_admin_settings(&$form, $settings = array()) { 199 if (empty($settings)) { 200 $settings = array( 201 'page_manager_term_view_type' => variable_get('page_manager_term_view_type', 'multiple'), 202 'page_manager_taxonomy_breadcrumb' => variable_get('page_manager_taxonomy_breadcrumb', TRUE), 203 ); 204 } 205 206 $form['page_manager_term_view_type'] = array( 207 '#type' => 'radios', 208 '#title' => t('Allow multiple terms on taxonomy/term/%term'), 209 '#options' => array('single' => t('Single term'), 'multiple' => t('Multiple terms')), 210 '#description' => t('By default, Drupal allows multiple terms as an argument by separating them with commas or plus signs. If you set this to single, that feature will be disabled.'), 211 '#default_value' => $settings['page_manager_term_view_type'], 212 ); 213 $form['page_manager_taxonomy_breadcrumb'] = array( 214 '#title' => t('Inject hierarchy of first term into breadcrumb trail'), 215 '#type' => 'checkbox', 216 '#default_value' => $settings['page_manager_taxonomy_breadcrumb'], 217 '#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'), 218 ); 219 } 220 221 /** 222 * Callback to enable/disable the page from the UI. 223 */ 224 function page_manager_term_view_enable($cache, $status) { 225 variable_set('page_manager_term_view_disabled', $status); 226 227 // Set a global flag so that the menu routine knows it needs 228 // to set a message if enabling cannot be done. 229 if (!$status) { 230 $GLOBALS['page_manager_enabling_term_view'] = TRUE; 231 } 232 } 233 234 /** 235 * Provide a nice administrative summary of the page so an admin can see at a 236 * glance what this page does and how it is configured. 237 */ 238 function page_manager_term_view_admin_summary($task, $subtask) { 239 $task_name = page_manager_make_task_name($task['name'], $subtask['name']); 240 241 $rows[] = array( 242 array('class' => t('page-summary-label'), 'data' => t('Path')), 243 array('class' => t('page-summary-data'), 'data' => 'taxonomy/term/%term'), 244 array('class' => t('page-summary-operation'), 'data' => ''), 245 ); 246 247 $rows[] = array( 248 array('class' => t('page-summary-label'), 'data' => t('Access')), 249 array('class' => t('page-summary-data'), 'data' => t('This page is publicly accessible.')), 250 array('class' => t('page-summary-operation'), 'data' => ''), 251 ); 252 253 $menu = t('No menu entry'); 254 255 $rows[] = array( 256 array('class' => t('page-summary-label'), 'data' => t('Menu')), 257 array('class' => t('page-summary-data'), 'data' => $menu), 258 array('class' => t('page-summary-operation'), 'data' => ''), 259 ); 260 261 if (variable_get('page_manager_term_view_type', 'multiple') == 'multiple') { 262 $message = t('Multiple terms may be used, separated by , or +.'); 263 } 264 else { 265 $message = t('Only a single term may be used.'); 266 } 267 268 $rows[] = array( 269 array('class' => t('page-summary-label'), 'data' => t('%term')), 270 array('class' => t('page-summary-data'), 'data' => $message), 271 array('class' => t('page-summary-operation'), 'data' => ''), 272 ); 273 274 if (variable_get('page_manager_taxonomy_breadcrumb', TRUE)) { 275 $message = t('Breadcrumb trail will contain taxonomy term hierarchy'); 276 } 277 else { 278 $message = t('Breadcrumb trail will not contain taxonomy term hiearchy.'); 279 } 280 281 $rows[] = array( 282 array('class' => t('page-summary-label'), 'data' => t('Breadcrumb')), 283 array('class' => t('page-summary-data'), 'data' => $message), 284 array('class' => t('page-summary-operation'), 'data' => ''), 285 ); 286 287 $output = theme('table', array(), $rows, array('id' => 'page-manager-page-summary')); 288 return $output; 289 }
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 |