| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: panels_mini_ui.class.php,v 1.1.2.5 2010/08/21 20:46:36 merlinofchaos Exp $ 3 4 class panels_mini_ui extends ctools_export_ui { 5 function init($plugin) { 6 parent::init($plugin); 7 ctools_include('context'); 8 } 9 10 function list_form(&$form, &$form_state) { 11 ctools_include('plugins', 'panels'); 12 $this->layouts = panels_get_layouts(); 13 14 parent::list_form($form, $form_state); 15 16 $categories = $layouts = array('all' => t('- All -')); 17 foreach ($this->items as $item) { 18 $categories[$item->category] = $item->category ? $item->category : t('Mini panels'); 19 } 20 21 $form['top row']['category'] = array( 22 '#type' => 'select', 23 '#title' => t('Category'), 24 '#options' => $categories, 25 '#default_value' => 'all', 26 '#weight' => -10, 27 ); 28 29 foreach ($this->layouts as $name => $plugin) { 30 $layouts[$name] = $plugin['title']; 31 } 32 33 $form['top row']['layout'] = array( 34 '#type' => 'select', 35 '#title' => t('Layout'), 36 '#options' => $layouts, 37 '#default_value' => 'all', 38 '#weight' => -9, 39 ); 40 } 41 42 function list_filter($form_state, $item) { 43 if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) { 44 return TRUE; 45 } 46 47 if ($form_state['values']['layout'] != 'all' && $form_state['values']['layout'] != $item->display->layout) { 48 return TRUE; 49 } 50 51 return parent::list_filter($form_state, $item); 52 } 53 54 function list_sort_options() { 55 return array( 56 'disabled' => t('Enabled, title'), 57 'title' => t('Title'), 58 'name' => t('Name'), 59 'category' => t('Category'), 60 'storage' => t('Storage'), 61 'layout' => t('Layout'), 62 ); 63 } 64 65 function list_build_row($item, &$form_state, $operations) { 66 // Set up sorting 67 switch ($form_state['values']['order']) { 68 case 'disabled': 69 $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title; 70 break; 71 case 'title': 72 $this->sorts[$item->name] = $item->admin_title; 73 break; 74 case 'name': 75 $this->sorts[$item->name] = $item->name; 76 break; 77 case 'category': 78 $this->sorts[$item->name] = ($item->category ? $item->category : t('Mini panels')) . $item->admin_title; 79 break; 80 case 'layout': 81 $this->sorts[$item->name] = $item->display->layout . $item->admin_title; 82 break; 83 case 'storage': 84 $this->sorts[$item->name] = $item->type . $item->admin_title; 85 break; 86 } 87 88 $layout = !empty($this->layouts[$item->display->layout]) ? $this->layouts[$item->display->layout]['title'] : t('Missing layout'); 89 $category = $item->category ? check_plain($item->category) : t('Mini panels'); 90 91 $this->rows[$item->name] = array( 92 'data' => array( 93 array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'), 94 array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'), 95 array('data' => $category, 'class' => 'ctools-export-ui-category'), 96 array('data' => $layout, 'class' => 'ctools-export-ui-layout'), 97 array('data' => $item->type, 'class' => 'ctools-export-ui-storage'), 98 array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'), 99 ), 100 'title' => !empty($item->admin_description) ? check_plain($item->admin_description) : '', 101 'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled', 102 ); 103 } 104 105 function list_table_header() { 106 return array( 107 array('data' => t('Title'), 'class' => 'ctools-export-ui-title'), 108 array('data' => t('Name'), 'class' => 'ctools-export-ui-name'), 109 array('data' => t('Category'), 'class' => 'ctools-export-ui-category'), 110 array('data' => t('Layout'), 'class' => 'ctools-export-ui-layout'), 111 array('data' => t('Storage'), 'class' => 'ctools-export-ui-storage'), 112 array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'), 113 ); 114 } 115 116 function edit_form(&$form, &$form_state) { 117 // Get the basic edit form 118 parent::edit_form($form, $form_state); 119 120 $form['category'] = array( 121 '#type' => 'textfield', 122 '#size' => 24, 123 '#default_value' => $form_state['item']->category, 124 '#title' => t('Category'), 125 '#description' => t("The category that this mini-panel will be grouped into on the Add Content form. Only upper and lower-case alphanumeric characters are allowed. If left blank, defaults to 'Mini panels'."), 126 ); 127 128 $form['title']['#title'] = t('Title'); 129 $form['title']['#description'] = t('The title for this mini panel. It can be overridden in the block configuration.'); 130 } 131 132 /** 133 * Validate submission of the mini panel edit form. 134 */ 135 function edit_form_basic_validate($form, &$form_state) { 136 parent::edit_form_validate($form, $form_state); 137 if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) { 138 form_error($form['category'], t('Categories may contain only alphanumerics or spaces.')); 139 } 140 } 141 142 function edit_form_submit(&$form, &$form_state) { 143 parent::edit_form_submit($form, $form_state); 144 $form_state['item']->category = $form_state['values']['category']; 145 } 146 147 function edit_form_context(&$form, &$form_state) { 148 ctools_include('context-admin'); 149 ctools_context_admin_includes(); 150 ctools_add_css('ruleset'); 151 152 $form['right'] = array( 153 '#prefix' => '<div class="ctools-right-container">', 154 '#suffix' => '</div>', 155 ); 156 157 $form['left'] = array( 158 '#prefix' => '<div class="ctools-left-container clear-block">', 159 '#suffix' => '</div>', 160 ); 161 162 // Set this up and we can use CTools' Export UI's built in wizard caching, 163 // which already has callbacks for the context cache under this name. 164 $module = 'ctools_export_ui-' . $this->plugin['name']; 165 $name = $this->edit_cache_get_key($form_state['item'], $form_state['form type']); 166 167 ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name); 168 ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name); 169 ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name); 170 } 171 172 function edit_form_context_submit(&$form, &$form_state) { 173 // Prevent this from going to edit_form_submit(); 174 } 175 176 function edit_form_layout(&$form, &$form_state) { 177 ctools_include('common', 'panels'); 178 ctools_include('display-layout', 'panels'); 179 ctools_include('plugins', 'panels'); 180 181 // @todo -- figure out where/how to deal with this. 182 $form_state['allowed_layouts'] = 'panels_mini'; 183 184 if ($form_state['op'] == 'add' && empty($form_state['item']->display)) { 185 $form_state['item']->display = panels_new_display(); 186 } 187 188 $form_state['display'] = &$form_state['item']->display; 189 190 // Tell the Panels form not to display buttons. 191 $form_state['no buttons'] = TRUE; 192 193 // Change the #id of the form so the CSS applies properly. 194 $form['#id'] = 'panels-choose-layout'; 195 $form = array_merge($form, panels_choose_layout($form_state)); 196 197 if ($form_state['op'] == 'edit') { 198 $form['buttons']['next']['#value'] = t('Change'); 199 } 200 } 201 202 /** 203 * Validate that a layout was chosen. 204 */ 205 function edit_form_layout_validate(&$form, &$form_state) { 206 $display = &$form_state['display']; 207 if (empty($form_state['values']['layout'])) { 208 form_error($form['layout'], t('You must select a layout.')); 209 } 210 if ($form_state['op'] == 'edit') { 211 if ($form_state['values']['layout'] == $display->layout) { 212 form_error($form['layout'], t('You must select a different layout if you wish to change layouts.')); 213 } 214 } 215 } 216 217 /** 218 * A layout has been selected, set it up. 219 */ 220 function edit_form_layout_submit(&$form, &$form_state) { 221 $display = &$form_state['display']; 222 if ($form_state['op'] == 'edit') { 223 if ($form_state['values']['layout'] != $display->layout) { 224 $form_state['item']->temp_layout = $form_state['values']['layout']; 225 $form_state['clicked_button']['#next'] = 'move'; 226 } 227 } 228 else { 229 $form_state['item']->display->layout = $form_state['values']['layout']; 230 } 231 } 232 233 /** 234 * When a layout is changed, the user is given the opportunity to move content. 235 */ 236 function edit_form_move(&$form, &$form_state) { 237 $form_state['display'] = &$form_state['item']->display; 238 $form_state['layout'] = $form_state['item']->temp_layout; 239 240 ctools_include('common', 'panels'); 241 ctools_include('display-layout', 'panels'); 242 ctools_include('plugins', 'panels'); 243 244 // Tell the Panels form not to display buttons. 245 $form_state['no buttons'] = TRUE; 246 247 // Change the #id of the form so the CSS applies properly. 248 $form = array_merge($form, panels_change_layout($form_state)); 249 250 // This form is outside the normal wizard list, so we need to specify the 251 // previous/next forms. 252 $form['buttons']['previous']['#next'] = 'layout'; 253 $form['buttons']['next']['#next'] = 'content'; 254 } 255 256 function edit_form_move_submit(&$form, &$form_state) { 257 panels_change_layout_submit($form, $form_state); 258 } 259 260 function edit_form_content(&$form, &$form_state) { 261 ctools_include('ajax'); 262 ctools_include('plugins', 'panels'); 263 ctools_include('display-edit', 'panels'); 264 ctools_include('context'); 265 266 // If we are cloning an item, we MUST have this cached for this to work, 267 // so make sure: 268 if ($form_state['form type'] == 'clone' && empty($form_state['item']->export_ui_item_is_cached)) { 269 $this->edit_cache_set($form_state['item'], 'clone'); 270 } 271 272 $cache = panels_edit_cache_get('panels_mini:' . $this->edit_cache_get_key($form_state['item'], $form_state['form type'])); 273 274 $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display); 275 $form_state['renderer']->cache = &$cache; 276 277 $form_state['display'] = &$cache->display; 278 $form_state['content_types'] = $cache->content_types; 279 // Tell the Panels form not to display buttons. 280 $form_state['no buttons'] = TRUE; 281 $form_state['display_title'] = !empty($cache->display_title); 282 283 $form = array_merge($form, panels_edit_display_form($form_state)); 284 // Make sure the theme will work since our form id is different. 285 $form['#theme'] = 'panels_edit_display_form'; 286 } 287 288 function edit_form_content_submit(&$form, &$form_state) { 289 panels_edit_display_form_submit($form, $form_state); 290 $form_state['item']->display = $form_state['display']; 291 } 292 }
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 |