You are here

function panels_save_display in Panels 6.3

Same name and namespace in other branches
  1. 8.3 panels.module \panels_save_display()
  2. 5.2 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

Related topics

6 calls to panels_save_display()
panels_edit_cache_save in ./panels.module
Method to allow modules to provide their own mechanism to write the cache used in the display editor.
panels_mini_save in panels_mini/panels_mini.module
Write a mini panel to the database.
panels_node_insert in panels_node/panels_node.module
Implementation of hook_insert().
panels_panel_context_save in plugins/task_handlers/panel_context.inc
Callback to allow the handler to react to being saved.
panels_renderer_editor::edit in plugins/display_renderers/panels_renderer_editor.class.php

... See full list

File

./panels.module, line 836
panels.module

Code

function panels_save_display(&$display) {
  $update = isset($display->did) && is_numeric($display->did) ? array(
    'did',
  ) : array();
  drupal_write_record('panels_display', $display, $update);
  $pids = array();
  if ($update) {

    // 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;
    }
  }

  // update all the panes
  ctools_include('plugins', 'panels');
  ctools_include('content');
  foreach ($display->panels as $id => $panes) {
    $position = 0;
    $new_panes = array();
    foreach ((array) $panes as $pid) {
      if (!isset($display->content[$pid])) {
        continue;
      }
      $pane = $display->content[$pid];
      $type = ctools_get_content_type($pane->type);
      $pane->position = $position++;
      $pane->did = $display->did;
      $old_pid = $pane->pid;
      drupal_write_record('panels_pane', $pane, is_numeric($pid) ? array(
        'pid',
      ) : array());
      if ($pane->pid != $old_pid) {

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

        // If the title pane was one of our panes that just got its ID changed,
        // we need to change it in the database, too.
        if (isset($display->title_pane) && $display->title_pane == $old_pid) {
          $display->title_pane = $pane->pid;

          // Do a simple update query to write it so we don't have to rewrite
          // the whole record. We can't just save writing the whole record here
          // because it was needed to get the did. Chicken, egg, more chicken.
          db_query("UPDATE {panels_display} SET title_pane = %d WHERE did = %d", $pane->pid, $display->did);
        }
      }

      // re-add this to the list of content for this panel.
      $new_panes[] = $pane->pid;

      // Remove this from the list of panes scheduled for deletion.
      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);

  // Allow other modules to take action when a display is saved.
  module_invoke_all('panels_display_save', $display);

  // Log the change to watchdog, using the same style as node.module
  $watchdog_args = array(
    '%did' => $display->did,
  );
  if (!empty($display->title)) {
    $watchdog_args['%title'] = $display->title;
    watchdog('content', 'Panels: saved display "%title" with display id %did', $watchdog_args, WATCHDOG_NOTICE);
  }
  else {
    watchdog('content', 'Panels: saved display with id %did', $watchdog_args, WATCHDOG_NOTICE);
  }

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