You are here

function panels_change_layout in Panels 6.2

Same name and namespace in other branches
  1. 5.2 includes/display_edit.inc \panels_change_layout()
  2. 6.3 includes/display-layout.inc \panels_change_layout()
  3. 7.3 includes/display-layout.inc \panels_change_layout()

Form definition for the display layout converter.

This form is only triggered if the user attempts to change the layout for a display that has already had content assigned to it. It allows the user to select where the panes located in to-be-deleted panels should be relocated to.

Parameters

array $form: A structured FAPI $form array.

object $display instanceof panels_display \n: The panels_display object that was modified on the preceding display layout editing form.

string $new_layout_id: A string containing the name of the layout the display is to be converted to. These strings correspond exactly to the filenames of the *.inc files in panels/layouts. So, if the new layout that's been selected is the 'Two Column bricks' layout, then $new_layout_id will be 'twocol_bricks', corresponding to panels/layouts/twocol_bricks.inc.

1 string reference to 'panels_change_layout'
_panels_edit_layout in includes/display-layout.inc
Handle calling and processing of the form for editing display layouts.

File

includes/display-layout.inc, line 161
Handle the forms for changing a display's layout.

Code

function panels_change_layout(&$form_state) {
  $display =& $form_state['display'];
  $new_layout = panels_get_layout($form_state['layout']);
  $new_layout_panels = panels_get_panels($new_layout, $display);
  $options = $new_layout_panels;
  $keys = array_keys($options);
  $default = current($options);
  $old_layout = panels_get_layout($display->layout);
  $form['container'] = array(
    '#prefix' => '<div class="change-layout-display">',
    '#suffix' => '</div>',
  );
  $form['container']['old_layout'] = array(
    '#value' => panels_print_layout_icon($display->layout, $old_layout, check_plain($old_layout['title'])),
  );
  $form['container']['right_arrow'] = array(
    '#value' => theme('image', drupal_get_path('module', 'panels') . '/images/go-right.png'),
  );
  $form['container']['new_layout'] = array(
    '#value' => panels_print_layout_icon($form_state['layout'], $new_layout, check_plain($new_layout['title'])),
  );
  $form['container-clearer'] = array(
    // TODO: FIx this ot use clear-block instead
    '#value' => '<div style="clear: both;"></div>',
  );
  $form['old'] = array(
    '#tree' => true,
    '#prefix' => '<div class="panels-layout-list">',
    '#suffix' => '</div>',
  );
  $old_layout_panels = panels_get_panels($old_layout, $display);
  if (empty($display->panels)) {
    $form['old'] = array(
      '#prefix' => '<div>',
      '#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.'),
      '#suffix' => '</div>',
    );
  }
  foreach ($display->panels as $id => $content) {
    $form['old'][$id] = array(
      '#type' => 'select',
      '#title' => t('Move content in @layout to', array(
        '@layout' => $old_layout_panels[$id],
      )),
      '#options' => $options,
      '#default_value' => array_key_exists($id, $options) ? $id : $default,
    );
  }
  $form['back'] = array(
    '#type' => 'submit',
    '#value' => t('Back'),
    '#submit' => array(
      'panels_choose_layout_back',
    ),
  );
  if (empty($form_state['no buttons'])) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => $form_state['finish'],
      '#submit' => array(
        'panels_change_layout_submit',
      ),
      '#save-display' => TRUE,
    );
  }
  return $form;
}