You are here

function panels_choose_layout in Panels 6.2

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

Form definition for the display layout editor.

1 string reference to 'panels_choose_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 73
Handle the forms for changing a display's layout.

Code

function panels_choose_layout(&$form_state) {
  $display =& $form_state['display'];
  $allowed_layouts = $form_state['allowed_layouts'];

  // @todo -- refactor the allowed layouts stuff for better code encapsulation.
  // module_name has been provided; the data was saved by the api_save() method.
  if (is_string($allowed_layouts)) {
    $allowed_layouts = unserialize(variable_get($allowed_layouts . "_allowed_layouts", serialize('')));
  }

  // if no parameter was provided, or the variable_get failed
  if (!$allowed_layouts) {

    // tries to load the common panels allowed layouts
    $allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize('')));
    if (!$allowed_layouts) {

      // still no dice. simply creates a dummy version where all layouts
      // are allowed.
      $allowed_layouts = new panels_allowed_layouts();
      $allowed_layouts->allow_new = TRUE;
    }
  }

  // sanitize allowed layout listing; this is redundant if the
  // $allowed_layouts param was null, but the data is cached anyway
  $allowed_layouts
    ->sync_with_available();
  $allowed = array_filter($allowed_layouts->allowed_layout_settings);
  $layouts = array();
  $available_layouts = panels_get_layouts();
  foreach ($available_layouts as $layout_key => $layout_settings) {
    if (!empty($allowed[$layout_key])) {
      $layouts[$layout_key] = $layout_settings;
    }
  }
  foreach ($layouts as $id => $layout) {
    $options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
  }
  drupal_add_js(panels_get_path('js/layout.js'));
  $form['layout'] = array(
    '#type' => 'radios',
    '#title' => t('Choose layout'),
    '#options' => $options,
    '#default_value' => in_array($display->layout, array_keys($layouts)) ? $display->layout : NULL,
  );
  $form['clearer'] = array(
    // TODO: Fix this to use clear-block instead
    '#value' => '<div style="clear: both;"></div>',
  );
  if (empty($form_state['no buttons'])) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Next'),
    );
  }
  return $form;
}