[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/panels/includes/ -> display-layout.inc (source)

   1  <?php
   2  // $Id: display-layout.inc,v 1.4.2.8 2010/07/20 20:26:18 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   *
   7   * Handle the forms for changing a display's layout.
   8   */
   9  
  10  /**
  11   * Handle calling and processing of the form for editing display layouts.
  12   *
  13   * Helper function for panels_edit_layout().
  14   *
  15   * @see panels_edit_layout() for details on the various behaviors of this function.
  16   */
  17  function _panels_edit_layout($display, $finish, $destination, $allowed_layouts) {
  18    ctools_include('common', 'panels');
  19    ctools_include('form');
  20  
  21    $form_state = array(
  22      'display' => &$display,
  23      'finish' => $finish,
  24      'destination' => $destination,
  25      'allowed_layouts' => $allowed_layouts,
  26      're_render' => FALSE,
  27      'no_redirect' => TRUE,
  28    );
  29  
  30    $change_form_state = $form_state;
  31  
  32    $change_form = FALSE;
  33  
  34    // Examine $_POST to see which form they're currently using.
  35    if (empty($_POST) || empty($_POST['form_id']) || $_POST['form_id'] != 'panels_change_layout') {
  36      $output = ctools_build_form('panels_choose_layout', $form_state);
  37      if (empty($output)) {
  38        // upon submission go to next form.
  39        $change_form_state['layout'] = $_SESSION['layout'][$display->did] = $form_state['layout'];
  40        $change_form = TRUE;
  41      }
  42    }
  43    else {
  44      $change_form_state['layout'] = $_SESSION['layout'][$display->did];
  45      $change_form = TRUE;
  46    }
  47  
  48    if ($change_form) {
  49      $output = ctools_build_form('panels_change_layout', $change_form_state);
  50      if (empty($output)) {
  51        if (isset($change_form_state['back'])) {
  52          unset($_POST);
  53          return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
  54        }
  55  
  56        if (!empty($change_form_state['clicked_button']['#save-display'])) {
  57          drupal_set_message(t('Panel layout has been updated.'));
  58          panels_save_display($display);
  59        }
  60  
  61        if ($destination) {
  62          return panels_goto($destination);
  63        }
  64        return $change_form_state['display'];
  65      }
  66    }
  67    return $output;
  68  }
  69  
  70  /**
  71   * Form definition for the display layout editor.
  72   *
  73   * @ingroup forms
  74   */
  75  function panels_choose_layout(&$form_state) {
  76    $display = &$form_state['display'];
  77    ctools_include('common', 'panels');
  78    ctools_include('cleanstring');
  79  
  80    $layouts = panels_common_get_allowed_layouts($form_state['allowed_layouts']);
  81    $categories = array();
  82    $current = '';
  83    foreach ($layouts as $id => $layout) {
  84      $category = ctools_cleanstring($layout['category']);
  85      // Default category to first in case layout doesn't exist or there isn't one.
  86      if (empty($current)) {
  87        $current = $category;
  88      }
  89  
  90      $categories[$category] = $layout['category'];
  91      $options[$category][$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
  92  
  93      // Set current category to what is chosen.
  94      if ($id == $display->layout) {
  95        $current = $category;
  96      }
  97    }
  98  
  99    ctools_add_js('layout', 'panels');
 100  
 101    $form['categories'] = array(
 102      '#title' => t('Category'),
 103      '#type' => 'select',
 104      '#options' => $categories,
 105      '#default_value' => $current,
 106    );
 107  
 108    $form['layout'] = array(
 109      '#prefix' => '<div class="panels-choose-layout panels-layouts-checkboxes clear-block">',
 110      '#suffix' => '</div>',
 111    );
 112  
 113    // We set up the dependencies manually because these aren't really form
 114    // items. It's possible there's a simpler way to do this, but I could not
 115    // think of one at the time.
 116    $dependencies = array();
 117    foreach ($options as $category => $radios) {
 118      $dependencies['panels-layout-category-' . $category] = array(
 119        'values' => array('edit-categories' => array($category)),
 120        'num' => 1,
 121        'type' => 'hide',
 122      );
 123  
 124      $form['layout'][$category] = array(
 125        '#prefix' => '<div id="panels-layout-category-' . $category . '-wrapper"><div id="panels-layout-category-' . $category . '" class="form-checkboxes clear-block"><div class="panels-layouts-category">' . $categories[$category] . '</div>',
 126        '#suffix' => '</div></div>',
 127      );
 128  
 129      foreach ($radios as $key => $choice) {
 130        // Generate the parents as the autogenerator does, so we will have a
 131        // unique id for each radio button.
 132        $form['layout'][$category][$key] = array(
 133          '#type' => 'radio',
 134          '#title' => $choice,
 135          '#parents' => array('layout'),
 136          '#id' => form_clean_id('edit-layout-' . $key),
 137          '#return_value' => check_plain($key),
 138          '#default_value' => in_array($display->layout, array_keys($layouts)) ? $display->layout : NULL,
 139        );
 140      }
 141    }
 142  
 143    ctools_add_js('dependent');
 144    $js['CTools']['dependent'] = $dependencies;
 145    drupal_add_js($js, 'setting');
 146  
 147  
 148    if (empty($form_state['no buttons'])) {
 149      $form['submit'] = array(
 150        '#type' => 'submit',
 151        '#value' => t('Next'),
 152      );
 153    }
 154  
 155    return $form;
 156  }
 157  
 158  /**
 159   * Handle form submission of the display layout editor.
 160   */
 161  function panels_choose_layout_submit($form, &$form_state) {
 162    $form_state['layout'] = $form_state['values']['layout'];
 163  }
 164  
 165  /**
 166   * Form definition for the display layout converter.
 167   *
 168   * This form is only triggered if the user attempts to change the layout
 169   * for a display that has already had content assigned to it. It allows
 170   * the user to select where the panes located in to-be-deleted panels should
 171   * be relocated to.
 172   *
 173   * @ingroup forms
 174   *
 175   * @param array $form
 176   *  A structured FAPI $form array.
 177   * @param object $display instanceof panels_display \n
 178   *  The panels_display object that was modified on the preceding display layout
 179   *  editing form.
 180   * @param string $new_layout_id
 181   *  A string containing the name of the layout the display is to be converted to.
 182   *  These strings correspond exactly to the filenames of the *.inc files in panels/layouts.
 183   *  So, if the new layout that's been selected is the 'Two Column bricks' layout, then
 184   *  $new_layout_id will be 'twocol_bricks', corresponding to panels/layouts/twocol_bricks.inc.
 185   */
 186  function panels_change_layout(&$form_state) {
 187    $display = &$form_state['display'];
 188  
 189    $new_layout = panels_get_layout($form_state['layout']);
 190    $new_layout_panels = panels_get_regions($new_layout, $display);
 191  
 192    $options = $new_layout_panels;
 193    $keys = array_keys($options);
 194    $default = current($options);
 195  
 196    $old_layout = panels_get_layout($display->layout);
 197  
 198    $form['container'] = array(
 199      '#prefix' => '<div class="change-layout-display">',
 200      '#suffix' => '</div>',
 201    );
 202  
 203    $form['container']['old_layout'] = array(
 204      '#value' => panels_print_layout_icon($display->layout, $old_layout, check_plain($old_layout['title'])),
 205    );
 206  
 207    $form['container']['right_arrow'] = array(
 208      '#value' => theme('image', drupal_get_path('module', 'panels') . '/images/go-right.png'),
 209    );
 210    $form['container']['new_layout'] = array(
 211      '#value' => panels_print_layout_icon($form_state['layout'], $new_layout, check_plain($new_layout['title'])),
 212    );
 213  
 214    $form['container-clearer'] = array(
 215      // TODO: FIx this ot use clear-block instead
 216      '#value' => '<div style="clear: both;"></div>',
 217    );
 218  
 219    $form['old'] = array(
 220      '#tree' => true,
 221      '#prefix' => '<div class="panels-layout-list">',
 222      '#suffix' => '</div>',
 223    );
 224  
 225    $old_layout_panels = panels_get_regions($old_layout, $display);
 226    if (empty($display->panels)) {
 227      $form['old'] = array(
 228        '#prefix' => '<div>',
 229        '#value' => t('There is no content in the panel display. If there were content, you would be given an opportunity to select where in the new layout the old content would be placed. Select "Save" or "Continue" to proceed. This change will not be processed if you do not continue.'),
 230        '#suffix' => '</div>',
 231      );
 232    }
 233  
 234    foreach ($display->panels as $id => $content) {
 235      $form['old'][$id] = array(
 236        '#type' => 'select',
 237        '#title' => t('Move content in @layout to', array('@layout' => $old_layout_panels[$id])),
 238        '#options' => $options,
 239        '#default_value' => array_key_exists($id, $options) ? $id : $default,
 240      );
 241    }
 242  
 243    if (empty($form_state['no buttons'])) {
 244      $form['back'] = array(
 245        '#type' => 'submit',
 246        '#value' => t('Back'),
 247        '#submit' => array('panels_choose_layout_back'),
 248      );
 249  
 250      $form['submit'] = array(
 251        '#type' => 'submit',
 252        '#value' => $form_state['finish'],
 253        '#submit' => array('panels_change_layout_submit'),
 254        '#save-display' => TRUE,
 255      );
 256    }
 257    return $form;
 258  }
 259  
 260  /**
 261   * Handle submission of the change layout form.
 262   *
 263   * This submit handler will move panes around and save the display.
 264   */
 265  function panels_change_layout_submit($form, &$form_state) {
 266    $display = &$form_state['display'];
 267  
 268    if (!empty($form_state['values']['old'])) {
 269      foreach ($form_state['values']['old'] as $id => $new_id) {
 270        if (isset($display->panels[$id])) {
 271          if (!isset($content[$new_id])) {
 272            $content[$new_id] = array();
 273          }
 274          $content[$new_id] = array_merge($content[$new_id], $display->panels[$id]);
 275        }
 276        foreach ($content[$new_id] as $pid) {
 277          $display->content[$pid]->panel = $new_id;
 278        }
 279      }
 280  
 281      $display->panels = $content;
 282    }
 283  
 284    $display->layout = $form_state['layout'];
 285  }
 286  
 287  /**
 288   * Handle submission of the change layout form.
 289   *
 290   * This submit handler sets a flag on the form state, which is then used
 291   * by the calling wrapper to restart the process.
 292   */
 293  function panels_choose_layout_back($form, &$form_state) {
 294    $form_state['back'] = TRUE;
 295  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7