You are here

function panels_export_display in Panels 7.3

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

Exports the provided display into portable code.

This function is primarily intended as a mechanism for cloning displays. It generates an exact replica (in code) of the provided $display, with the exception that it replaces all ids (dids and pids) with place-holder values (consisting of the display or pane's uuid, with a 'new-' prefix).

Only once panels_save_display() is called on the code version of $display will the exported display be written to the database and permanently saved.

Parameters

object $display: This export function does no loading of additional data about the provided display. Consequently, the caller should make sure that all the desired data has been loaded into the $display before calling this function.

string $prefix: A string prefix that is prepended to each line of exported code. This is primarily used for prepending a double space when exporting so that the code indents and lines up nicely.

Return value

string $output The passed-in $display expressed as code, ready to be imported. Import by running eval($output) in the caller function; doing so will create a new $display variable with all the exported values. Note that if you have already defined a $display variable in the same scope as where you eval(), your existing $display variable WILL be overwritten.

See also

panels_page_export() or _panels_page_fetch_display() for samples.

Related topics

4 calls to panels_export_display()
panels_mini_export in panels_mini/panels_mini.module
Export a mini panel.
panels_node_export_node_alter in panels_node/panels_node.module
Implementation of hook_export_node_alter().
panels_panel_context_clone in plugins/task_handlers/panel_context.inc
When a handler is cloned, we have to clone the display.
panels_panel_context_export in plugins/task_handlers/panel_context.inc
Special handling for exporting a panel task handler.
1 string reference to 'panels_export_display'
panels_schema_3 in ./panels.install
Schema from the D6 version.

File

./panels.module, line 1235
Core functionality for the Panels engine.

Code

function panels_export_display($display, $prefix = '') {
  ctools_include('export');
  if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) {
    $display->uuid = ctools_uuid_generate();
  }
  $display->did = 'new-' . $display->uuid;
  $output = ctools_export_object('panels_display', $display, $prefix);

  // Initialize empty properties.
  $output .= $prefix . '$display->content = array()' . ";\n";
  $output .= $prefix . '$display->panels = array()' . ";\n";
  $panels = array();
  $title_pid = 0;
  if (!empty($display->content)) {
    $region_counters = array();
    foreach ($display->content as $pane) {
      if (!isset($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
        $pane->uuid = ctools_uuid_generate();
      }
      $pid = 'new-' . $pane->uuid;
      if ($pane->pid == $display->title_pane) {
        $title_pid = $pid;
      }
      $pane->pid = $pid;
      $output .= ctools_export_object('panels_pane', $pane, $prefix);
      $output .= $prefix . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
      if (!isset($region_counters[$pane->panel])) {
        $region_counters[$pane->panel] = 0;
      }
      $output .= $prefix . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ . '] = \'' . $pane->pid . "';\n";
    }
  }
  $output .= $prefix . '$display->hide_title = ';
  switch ($display->hide_title) {
    case PANELS_TITLE_FIXED:
      $output .= 'PANELS_TITLE_FIXED';
      break;
    case PANELS_TITLE_NONE:
      $output .= 'PANELS_TITLE_NONE';
      break;
    case PANELS_TITLE_PANE:
      $output .= 'PANELS_TITLE_PANE';
      break;
  }
  $output .= ";\n";
  $output .= $prefix . '$display->title_pane =' . " '{$title_pid}';\n";
  return $output;
}