function panels_save_display in Panels 6.2
Same name and namespace in other branches
- 8.3 panels.module \panels_save_display()
- 5.2 panels.module \panels_save_display()
- 6.3 panels.module \panels_save_display()
- 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
Related topics
8 calls to panels_save_display()
- 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().
- panels_page_save_import in panels_page/
panels_page.write.inc - Prepare an imported panel page for insertion into the database, then insert it.
- _panels_edit in includes/
display-edit.inc - Handle calling and processing of the form for editing display content.
- _panels_edit_layout in includes/
display-layout.inc - Handle calling and processing of the form for editing display layouts.
File
- ./
panels.module, line 682 - panels.module
Code
function panels_save_display(&$display) {
// @todo -- update all this to just use drupal_write_record or something like it.
if (!empty($display->did) && $display->did != 'new') {
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);
// Get a list of all panes currently in the database for this display so we can know if there
// are panes that need to be deleted. (i.e, aren't currently in our list of panes).
$result = db_query("SELECT pid FROM {panels_pane} WHERE did = %d", $display->did);
while ($pane = db_fetch_object($result)) {
$pids[$pane->pid] = $pane->pid;
}
}
else {
db_query("INSERT INTO {panels_display} (layout, layout_settings, panel_settings, cache, title, hide_title) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title);
$display->did = db_last_insert_id('panels_display', 'did');
$pids = array();
}
// 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++;
// make variables right.
$type = panels_get_content_type($pane->type);
$access = isset($pane->access) ? implode(', ', $pane->access) : '';
$visibility = !empty($type['visibility serialize']) ? serialize($pane->visibility) : $pane->visibility;
$pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
if (empty($pane->cache)) {
$pane->cache = array();
}
$v = array(
$display->did,
$pane->panel,
$pane->type,
$pane->subtype,
serialize($pane->configuration),
serialize($pane->cache),
$pane->shown,
$access,
$visibility,
$pane->position,
);
if (!is_numeric($pid)) {
unset($display->content[$pid]);
// doin it this way for readability
$f = 'did, panel, type, subtype, configuration, cache, shown, access, visibility, position';
$q = "%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d";
db_query("INSERT INTO {panels_pane} ({$f}) VALUES ({$q})", $v);
$pane->pid = db_last_insert_id('panels_pane', 'pid');
}
else {
$v[] = $pane->pid;
$f = "did = %d, panel = '%s', type = '%s', subtype = '%s', configuration = '%s', cache = '%s', shown = '%s', access = '%s', visibility = '%s', position = '%d'";
db_query("UPDATE {panels_pane} SET {$f} WHERE pid = %d", $v);
}
// and put it back so our pids and positions can be used
$display->content[$pane->pid] = $pane;
$new_panes[] = $pane->pid;
if (isset($pids[$pane->pid])) {
unset($pids[$pane->pid]);
}
}
$display->panels[$id] = $new_panes;
}
if (!empty($pids)) {
db_query("DELETE FROM {panels_pane} WHERE pid IN (" . db_placeholders($pids) . ")", $pids);
}
// Clear any cached content for this display.
panels_clear_cached_content($display);
// to be nice, even tho we have a reference.
return $display;
}