function panels_mini_save in Panels 5.2
Same name and namespace in other branches
- 6.3 panels_mini/panels_mini.module \panels_mini_save()
- 6.2 panels_mini/panels_mini.module \panels_mini_save()
- 7.3 panels_mini/panels_mini.module \panels_mini_save()
Save a mini panel.
5 calls to panels_mini_save()
- panels_mini_context_form_submit in panels_mini/
panels_mini.module - Process submission of the mini panel edit form.
- panels_mini_edit_content in panels_mini/
panels_mini.module - Pass through to the panels content editor.
- panels_mini_edit_form_submit in panels_mini/
panels_mini.module - Process submission of the mini panel edit form.
- panels_mini_edit_layout in panels_mini/
panels_mini.module - Pass through to the panels layout editor.
- panels_mini_edit_layout_settings in panels_mini/
panels_mini.module - Pass through to the panels layout settings editor.
File
- panels_mini/
panels_mini.module, line 1098 - panels_mini.module
Code
function panels_mini_save(&$panel_mini) {
$fields = $types = $values = $pairs = array();
// Save the display if one was given to us.
if (!empty($panel_mini->display)) {
$display = panels_save_display($panel_mini->display);
}
// Ensure empty values get translated correctly.
// Also make sure we don't mess up the original.
$mini_clone = drupal_clone(panels_mini_sanitize($panel_mini));
// If pid is set to our "magic value", this is an insert, otherwise an update.
$insert = $mini_clone->pid && $mini_clone->pid == 'new';
// Build arrays of fields and types (resp. pairs of both) and of values.
foreach (panels_mini_fields() as $field => $type) {
// Skip empty values.
if (isset($mini_clone->{$field})) {
if ($insert) {
$fields[] = $field;
$types[] = $type;
}
else {
$pairs[] = "{$field} = {$type}";
}
// Build the $values array, serializing some fields.
$serialize = in_array($field, array(
'contexts',
'requiredcontexts',
'relationships',
));
$values[] = $serialize ? serialize($mini_clone->{$field}) : $mini_clone->{$field};
}
}
if ($insert) {
// Determine the new primary key.
$mini_clone->pid = db_next_id('{panels_mini}_pid');
// Build the query adding the new primary key and the did.
$sql = 'INSERT INTO {panels_mini} (' . implode(', ', $fields) . ', did, pid) VALUES (' . implode(', ', $types) . ', %d, %d)';
$values[] = $display->did;
}
else {
// Build the query filtering by the primary key.
$sql = 'UPDATE {panels_mini} SET ' . implode(', ', $pairs) . ' WHERE pid = %d';
}
$values[] = $mini_clone->pid;
db_query($sql, $values);
return $mini_clone->pid;
}