You are here

function _panels_page_insert in Panels 5.2

Same name and namespace in other branches
  1. 6.2 panels_page/panels_page.write.inc \_panels_page_insert()

Insert a new panel page into the database.

1 call to _panels_page_insert()
panels_page_save in panels_page/panels_page.admin.inc
Main entry point for panels_page save functions.

File

panels_page/panels_page.admin.inc, line 1016
panels_page.admin.inc

Code

function _panels_page_insert(&$panel_page) {
  $fields = $types = $values = array();

  // Save the primary display, thus creating a $display->did.
  panels_save_display($panel_page->primary);
  $panel_page->did = $panel_page->primary->did;
  $panel_page->pid = db_next_id('{panels_page}_pid');
  $clone = drupal_clone($panel_page);

  // Add these manually rather than putting them in panels_page_fields() itself
  $all_fields = array_merge(panels_page_fields(), array(
    "pid" => "%d",
    "did" => "%d",
  ));
  foreach ($all_fields as $field => $placeholder) {
    if (isset($panel_page->{$field})) {
      $fields[] = $field;
      $placeholders[] = $placeholder;
      $values[] = _panels_page_save_value($field, $clone->{$field});
    }
  }

  // Build the query adding the new pid and did.
  $sql = 'INSERT INTO {panels_page} (' . implode(', ', $fields) . ') VALUES (' . implode(' , ', $placeholders) . ')';
  db_query($sql, $values);
  menu_rebuild();

  // Return the pid for convenience.
  return $panel_page->pid;
}