[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7