You are here

function panels_page_context_form_submit in Panels 5.2

Same name and namespace in other branches
  1. 6.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 635
panels_page.admin.inc

Code

function panels_page_context_form_submit($form_id, $form_values) {
  $panel_page = $form_values['panel_page'];

  // Organize these from the common form.
  panels_common_save_context('argument', $panel_page->arguments, $form_values);
  panels_common_save_context('context', $panel_page->contexts, $form_values);
  panels_common_save_context('relationship', $panel_page->relationships, $form_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_save($panel_page);
  panels_common_cache_clear('panel_object:panel_page', $panel_page->name);
  menu_rebuild();
  if ($form_values['submit'] == t('Save and proceed')) {
    return "admin/panels/panel-page/{$panel_page->name}/edit/content";
  }
}