You are here

function panels_page_context_form_submit in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_page/panels_page.admin.inc \panels_page_context_form_submit()

Process submission of the panel page edit form.

File

panels_page/panels_page.admin.inc, line 676
panels_page.admin.inc

Code

function panels_page_context_form_submit($form, &$form_state) {
  $panel_page = $form_state['panel_page'];

  // Organize these from the common form.
  panels_common_save_context('argument', $panel_page->arguments, $form_state['values']);

  // Match up our displays, carry them forward and add new ones.
  $old_displays = $panel_page->displays;
  $panel_page->displays = array();
  foreach ($panel_page->arguments as $id => $argument) {
    $def = panels_get_argument($argument['name']);
    if (function_exists($def['displays'])) {

      // Figure out which instance of this particular argument type we're using.
      $displays = $def['displays']($argument['argument_settings'], $argument['id']);
      foreach ($displays as $did => $info) {
        $pdid = "argument_{$id}" . '-' . $did;
        if (isset($old_displays[$pdid])) {
          $panel_page->displays[$pdid] = $old_displays[$pdid];
          unset($old_displays[$pdid]);

          // ensure titles get updated if necessary
          $panel_page->displays[$pdid]['title'] = $info['title'];
        }
        else {
          $panel_page->displays[$pdid] = array(
            'did' => 'new',
            'title' => $info['title'],
            'default' => "argument_{$id}" . '-' . $info['default'],
            'argument_id' => $id,
            'context' => $info['context'],
          );
        }
      }
    }
  }

  // Remove remaining old displays.
  foreach ($old_displays as $id => $info) {
    if (is_numeric($info['did'])) {
      panels_delete_display($info['did']);
      drupal_set_message(t('Removed unused display @title', $info['title']));
    }
  }
  drupal_set_message(t('Your changes have been saved.'));
  panels_page_load_include('write');
  panels_page_save($panel_page);
  panels_cache_clear('panel_object:panel_page', $panel_page->name);
  menu_rebuild();
  if ($form_state['next']) {
    $form_state['redirect'] = "admin/panels/panel-page/{$panel_page->name}/edit/content";
  }
}