You are here

function panels_save_display in Panels 5.2

Same name and namespace in other branches
  1. 8.3 panels.module \panels_save_display()
  2. 6.3 panels.module \panels_save_display()
  3. 6.2 panels.module \panels_save_display()
  4. 7.3 panels.module \panels_save_display()

Save a display object.

Note a new $display only receives a real did once it is run through this function. Until then, it uses a string placeholder, 'new', in place of a real did. The same applies to all new panes (whether on a new $display or not); in addition, panes have sequential numbers appended, of the form 'new-1', 'new-2', etc.

Parameters

object $display instanceof panels_display \n: The display object to be saved. Passed by reference so the caller need not use the return value for any reason except convenience.

Return value

object $display instanceof panels_display \n

8 calls to panels_save_display()
panels_choose_layout_submit in includes/display_edit.inc
Handle form submission of the display layout editor.
panels_edit_display_submit in includes/display_edit.inc
Handle form submission of the display content editor.
panels_edit_layout_settings_form_submit in includes/display_edit.inc
panels_mini_save in panels_mini/panels_mini.module
Save a mini panel.
panels_node_insert in panels_node/panels_node.module
Implementation of hook_insert().

... See full list

File

./panels.module, line 751
panels.module Core API for Panels. Provides display editing and rendering capabilities.

Code

function panels_save_display(&$display) {
  if ($display->did && $display->did != 'new') {
    if (empty($display->cache)) {
      $display->cache = array();
    }
    db_query("UPDATE {panels_display} SET layout = '%s', layout_settings = '%s', panel_settings = '%s', cache = '%s', title = '%s', hide_title = %d WHERE did = %d", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title, $display->did);
    db_query("DELETE FROM {panels_pane} WHERE did = %d", $display->did);
  }
  else {
    $display->did = db_next_id("{panels_display}_did");
    db_query("INSERT INTO {panels_display} (did, layout, layout_settings, panel_settings, cache, title, hide_title) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $display->did, $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title);
  }

  // update all the panes
  panels_load_include('plugins');
  foreach ((array) $display->panels as $id => $panes) {
    $position = 0;
    $new_panes = array();
    foreach ((array) $panes as $pid) {
      $pane = $display->content[$pid];
      $pane->position = $position++;
      if (!is_numeric($pid)) {
        unset($display->content[$pid]);
        $pane->pid = db_next_id("{panels_pane}_pid");
      }
      if (empty($pane->cache)) {
        $pane->cache = array();
      }
      $type = panels_get_content_type($pane->type);
      $access = isset($pane->access) ? implode(', ', $pane->access) : '';
      $visibility = $type['visibility serialize'] ? serialize($pane->visibility) : $pane->visibility;

      // doin it this way for readability
      $f = 'pid, did, panel, type, subtype, configuration, cache, shown, access, visibility, position';
      $q = "%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d";
      $pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
      $v = array(
        $pane->pid,
        $display->did,
        $pane->panel,
        $pane->type,
        $pane->subtype,
        serialize($pane->configuration),
        serialize($pane->cache),
        $pane->shown,
        $access,
        $visibility,
        $pane->position,
      );
      db_query("INSERT INTO {panels_pane} ({$f}) VALUES ({$q})", $v);

      // and put it back so our pids and positions can be used
      $display->content[$pane->pid] = $pane;
      $new_panes[] = $pane->pid;
    }
    $display->panels[$id] = $new_panes;
  }

  // Clear any cached content for this display.
  panels_clear_cached_content($display);

  // to be nice, even tho we have a reference.
  return $display;
}