| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: display-edit.inc,v 1.7.2.42 2010/07/26 19:44:29 merlinofchaos Exp $ 3 4 /* 5 * @file 6 * Core Panels API include file containing various display-editing functions. 7 * This includes all the basic editing forms (content, layout, layout settings) 8 * as well as the ajax modal forms associated with them. 9 */ 10 11 12 /** 13 * Handle calling and processing of the form for editing display content. 14 * 15 * Helper function for panels_edit(). 16 * 17 * @see panels_edit() for details on the various behaviors of this function. 18 */ 19 function _panels_edit($display, $destination, $content_types, $title = FALSE) { 20 $did = $display->did; 21 if (!$did) { 22 $display->did = $did = 'new'; 23 } 24 25 // Load the display being edited from cache, if possible. 26 if (!empty($_POST) && is_object($cache = panels_edit_cache_get($did))) { 27 $display = $cache->display; 28 } 29 else { 30 $cache = panels_edit_cache_get_default($display, $content_types, $title); 31 } 32 33 // Get a renderer. 34 $renderer = panels_get_renderer_handler('editor', $display); 35 $renderer->cache = $cache; 36 37 $output = $renderer->edit(); 38 if (is_object($output) && $destination) { 39 return panels_goto($destination); 40 } 41 return $output; 42 } 43 44 /** 45 * Form definition for the panels display editor 46 * 47 * No validation function is necessary, as all 'validation' is handled 48 * either in the lead-up to form rendering (through the selection of 49 * specified content types) or by the validation functions specific to 50 * the ajax modals & content types. 51 * 52 * @ingroup forms 53 * @see panels_edit_display_submit() 54 */ 55 function panels_edit_display_form(&$form_state) { 56 $display = &$form_state['display']; 57 $renderer = &$form_state['renderer']; 58 59 // Make sure there is a valid cache key. 60 $cache_key = isset($display->cache_key) ? $display->cache_key : $display->did; 61 $display->cache_key = $cache_key; 62 63 // Annoyingly, theme doesn't have access to form_state so we have to do this. 64 $form['#display'] = $display; 65 66 // The flexible layout maker wants to be able to edit a display without 67 // actually editing a display, so we provide this 'setting' to allow 68 // that to go away. 69 if (empty($form_state['no display settings'])) { 70 $links = $renderer->get_display_links(); 71 } 72 else { 73 $links = ''; 74 } 75 $form['hide']['display-settings'] = array( 76 '#value' => $links, 77 ); 78 79 $form += panels_edit_display_settings_form($form_state); 80 81 $form['panel'] = array('#tree' => TRUE); 82 $form['panel']['pane'] = array('#tree' => TRUE); 83 84 $form['display'] = array( 85 '#value' => $renderer->render(), 86 ); 87 88 foreach ($renderer->plugins['layout']['panels'] as $region_id => $title) { 89 // Make sure we at least have an empty array for all possible locations. 90 if (!isset($display->panels[$region_id])) { 91 $display->panels[$region_id] = array(); 92 } 93 94 $form['panel']['pane'][$region_id] = array( 95 // Use 'hidden' instead of 'value' so the js can access it. 96 '#type' => 'hidden', 97 '#default_value' => implode(',', (array) $display->panels[$region_id]), 98 ); 99 } 100 101 if (empty($form_state['no buttons'])) { 102 $form['buttons']['submit'] = array( 103 '#type' => 'submit', 104 '#value' => t('Save'), 105 '#id' => 'panels-dnd-save', 106 '#submit' => array('panels_edit_display_form_submit'), 107 '#save-display' => TRUE, 108 ); 109 $form['buttons']['cancel'] = array( 110 '#type' => 'submit', 111 '#value' => t('Cancel'), 112 ); 113 } 114 115 // Build up the preview portion of the form, if necessary. 116 if (empty($form_state['no preview'])) { 117 $form['preview'] = array( 118 '#tree' => TRUE, 119 '#prefix' => '<h2>' . t('Live preview') . '</h2>' . '<div id="panels-live-preview">', 120 '#suffix' => '</div>', 121 ); 122 123 ctools_context_replace_form($form['preview'], $display->context); 124 $form['preview']['button'] = array( 125 '#type' => 'submit', 126 '#value' => t('Preview'), 127 '#attributes' => array('class' => 'ctools-use-ajax'), 128 '#id' => 'panels-live-preview-button', 129 '#submit' => array('panels_edit_display_form_submit', 'panels_edit_display_form_preview'), 130 ); 131 } 132 133 return $form; 134 } 135 136 /** 137 * Handle form submission of the display content editor. 138 * 139 * This reads the location of the various panes from the form, which will 140 * have been modified from the ajax, rearranges them and then saves 141 * the display. 142 */ 143 function panels_edit_display_form_submit($form, &$form_state) { 144 $display = &$form_state['display']; 145 146 $old_content = $display->content; 147 $display->content = array(); 148 149 if (!empty($form_state['values']['panel']['pane'])) { 150 foreach ($form_state['values']['panel']['pane'] as $panel_id => $panes) { 151 $display->panels[$panel_id] = array(); 152 if ($panes) { 153 $pids = explode(',', $panes); 154 // need to filter the array, b/c passing it in a hidden field can generate trash 155 foreach (array_filter($pids) as $pid) { 156 if ($old_content[$pid]) { 157 $display->panels[$panel_id][] = $pid; 158 $old_content[$pid]->panel = $panel_id; 159 $display->content[$pid] = $old_content[$pid]; 160 } 161 } 162 } 163 } 164 } 165 166 panels_edit_display_settings_form_submit($form, $form_state); 167 } 168 169 /** 170 * Submission of the preview button. Render the preview and put it into 171 * the preview widget area. 172 */ 173 function panels_edit_display_form_preview(&$form, &$form_state) { 174 $display = &$form_state['display']; 175 ctools_include('ajax'); 176 177 $display->context = ctools_context_replace_placeholders($display->context, $form_state['values']['preview']); 178 $display->skip_cache = TRUE; 179 $output = panels_render_display($display); 180 181 // Add any extra CSS that some layouts may have added specifically for this. 182 if (!empty($display->add_css)) { 183 $output = "<style type=\"text/css\">\n$display->add_css</style>\n" . $output; 184 } 185 186 $commands = array(); 187 $commands[] = array( 188 'command' => 'panel_preview', 189 'output' => $output, 190 ); 191 192 ctools_ajax_render($commands); 193 } 194 195 196 /** 197 * Form for display settings. 198 */ 199 function panels_edit_display_settings_form(&$form_state) { 200 $form = array(); 201 $display = &$form_state['display']; 202 203 $layout = panels_get_layout($display->layout); 204 $form_state['layout'] = $layout; 205 206 ctools_include('dependent'); 207 208 if ($form_state['display_title']) { 209 $form['display_title'] = array ( 210 '#tree' => TRUE, 211 ); 212 213 $form['display_title']['hide_title'] = array( 214 '#type' => 'select', 215 '#title' => t('Title type'), 216 '#default_value' => (int) $display->hide_title, 217 '#options' => array( 218 PANELS_TITLE_NONE => t('No title'), 219 PANELS_TITLE_FIXED => t('Manually set'), 220 PANELS_TITLE_PANE => t('From pane'), 221 ), 222 ); 223 224 $form['display_title']['title'] = array( 225 '#type' => 'textfield', 226 '#default_value' => $display->title, 227 '#title' => t('Title'), 228 '#description' => t('The title of this panel. If left blank, a default title may be used. Set to No Title if you want the title to actually be blank.'), 229 '#process' => array('ctools_dependent_process'), 230 '#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)), 231 ); 232 233 if (!empty($display->context)) { 234 $form['display_title']['title']['#description'] .= ' ' . t('You may use substitutions in this title.'); 235 236 // We have to create a manual fieldset because fieldsets do not support IDs. 237 // Use 'hidden' instead of 'markup' so that the process will run. 238 // Add js for collapsible fieldsets manually 239 drupal_add_js('misc/collapse.js'); 240 $form['display_title']['contexts_prefix'] = array( 241 '#type' => 'hidden', 242 '#id' => 'edit-display-substitutions', 243 '#prefix' => '<div><fieldset id="edit-display-substitutions" class="collapsed collapsible"><legend>' . t('Substitutions') . '</legend>', 244 '#process' => array('ctools_dependent_process'), 245 '#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)), 246 ); 247 248 $rows = array(); 249 foreach ($display->context as $context) { 250 foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) { 251 $rows[] = array( 252 check_plain($keyword), 253 t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)), 254 ); 255 } 256 } 257 258 $header = array(t('Keyword'), t('Value')); 259 $form['display_title']['contexts'] = array( 260 '#value' => theme('table', $header, $rows), 261 ); 262 $form['display_title']['contexts_suffix'] = array( 263 '#value' => '</fieldset></div>', 264 ); 265 } 266 } 267 268 // TODO doc the ability to do this as part of the API 269 if (!empty($layout['settings form']) && function_exists($layout['settings form'])) { 270 $form['layout_settings'] = $layout['settings form']($display, $layout, $display->layout_settings); 271 } 272 $form['layout_settings']['#tree'] = TRUE; 273 274 return $form; 275 } 276 277 /** 278 * Validate the layout settings form. 279 */ 280 function panels_edit_display_settings_form_validate($form, &$form_state) { 281 if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings validate')) { 282 $function($form_state['values']['layout_settings'], $form['layout_settings'], $form_state['display'], $form_state['layout'], $form_state['display']->layout_settings); 283 } 284 } 285 286 /** 287 * Store changes from the layout settings form. 288 */ 289 function panels_edit_display_settings_form_submit($form, &$form_state) { 290 $display = &$form_state['display']; 291 if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings submit')) { 292 $function($form_state['values']['layout_settings'], $display, $form_state['layout'], $display->layout_settings); 293 } 294 295 // Since not all layouts have layout settings, check here in case of notices. 296 if (isset($form_state['values']['layout_settings'])) { 297 $display->layout_settings = $form_state['values']['layout_settings']; 298 } 299 300 if (isset($form_state['values']['display_title']['title'])) { 301 $display->title = $form_state['values']['display_title']['title']; 302 $display->hide_title = $form_state['values']['display_title']['hide_title']; 303 } 304 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |