function edit() {
    $form_state = array(
      'display' => &$this->display,
      'renderer' => &$this,
      'content_types' => $this->cache->content_types,
      'no_redirect' => TRUE,
      'display_title' => !empty($this->cache->display_title),
      'cache key' => $this->display->cache_key,
    );

    $output = drupal_build_form('panels_edit_display_form', $form_state);
    if (empty($form_state['executed']) || !empty($form_state['clicked_button']['preview'])) {
      return $output;
    }

    if (!empty($form_state['clicked_button']['#save-display'])) {
      drupal_set_message(t('Panel content has been updated.'));
      panels_save_display($this->display);
    }
    else {
      drupal_set_message(t('Your changes have been discarded.'));
    }

    panels_cache_clear('display', $this->display->did);
    return $this->display;
  }
  function edit() {
    ctools_include('form');
    $form_state = array(
      'display' => &$this->display,
      'renderer' => &$this,
      'content_types' => $this->cache->content_types,
      're_render' => FALSE,
      'no_redirect' => TRUE,
      'display_title' => !empty($this->cache->display_title),
      'cache key' => $this->display->cache_key,
    );

    $output = ctools_build_form('panels_edit_display_form', $form_state);
    if ($output) {
      return $output;
    }

    // no output == submit
    if (!$output) {
      if (!empty($form_state['clicked_button']['#save-display'])) {
        drupal_set_message(t('Panel content has been updated.'));
        panels_save_display($this->display);
      }
      else {
        drupal_set_message(t('Your changes have been discarded.'));
      }

      panels_cache_clear('display', $this->display->did);
      return $this->display;
    }
  }
 function edit_form(&$form, &$form_state)
 {
     ctools_include('plugins', 'panels');
     // If the plugin is not set, then it should be provided as an argument:
     if (!isset($form_state['item']->plugin)) {
         $form_state['item']->plugin = $form_state['function args'][2];
     }
     parent::edit_form($form, $form_state);
     $form['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'), '#default_value' => $form_state['item']->category);
     ctools_include('context');
     ctools_include('display-edit', 'panels');
     ctools_include('content');
     // Provide actual layout admin UI here.
     // Create a display for editing:
     $cache_key = 'builder-' . $form_state['item']->name;
     // Load the display being edited from cache, if possible.
     if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) {
         $display =& $cache->display;
     } else {
         $content_types = ctools_content_get_available_types();
         panels_cache_clear('display', $cache_key);
         $cache = new stdClass();
         $display = panels_new_display();
         $display->did = $form_state['item']->name;
         $display->layout = $form_state['item']->plugin;
         $display->layout_settings = $form_state['item']->settings;
         $display->cache_key = $cache_key;
         $display->editing_layout = TRUE;
         $cache->display = $display;
         $cache->content_types = $content_types;
         $cache->display_title = FALSE;
         panels_edit_cache_set($cache);
     }
     // Set up lipsum content in all of the existing panel regions:
     $display->content = array();
     $display->panels = array();
     $custom = ctools_get_content_type('custom');
     $layout = panels_get_layout($display->layout);
     $regions = panels_get_regions($layout, $display);
     foreach ($regions as $id => $title) {
         $pane = panels_new_pane('custom', 'custom');
         $pane->pid = $id;
         $pane->panel = $id;
         $pane->configuration = ctools_content_get_defaults($custom, 'custom');
         $pane->configuration['title'] = 'Lorem Ipsum';
         $pane->configuration['body'] = $this->lipsum;
         $display->content[$id] = $pane;
         $display->panels[$id] = array($id);
     }
     $form_state['display'] =& $display;
     // Tell the Panels form not to display buttons.
     $form_state['no buttons'] = TRUE;
     $form_state['no display settings'] = TRUE;
     $form_state['cache_key'] = $cache_key;
     $form_state['content_types'] = $cache->content_types;
     $form_state['display_title'] = FALSE;
     $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
     $form_state['renderer']->cache =& $cache;
     $form = panels_edit_display_form($form, $form_state);
     // If we leave the standard submit handler, it'll try to reconcile
     // content from the input, but we've not exposed that to the user. This
     // makes previews work with the content we forced in.
     $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview');
 }