You are here

function panels_page_export in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_page/panels_page.module \panels_page_export()

Export a panel page into PHP code for use in import.

The code returned from can be used directly in panels_page_save().

2 calls to panels_page_export()
panels_page_export_page in panels_page/panels_page.admin.inc
panels_page_panels_exportables in panels_page/panels_page.module
Implementation of hook_panels_exportables().

File

panels_page/panels_page.write.inc, line 174
panels_page.write.inc

Code

function panels_page_export($panel_page, $prefix = '') {

  // Make sure the primary display is the current display.
  panels_page_fetch_display($panel_page);
  $output = '';
  $fields = panels_page_fields();
  $output .= $prefix . '$page = new stdClass()' . ";\n";
  $output .= $prefix . '  $page->pid = \'new\'' . ";\n";
  $output .= $prefix . '  $page->did = \'new\'' . ";\n";
  foreach (array_keys($fields) as $field) {
    if (isset($panel_page->{$field}) && !in_array($field, array(
      'displays',
      'contexts',
      'display',
      'pid',
      'did',
    ))) {
      $output .= $prefix . '  $page->' . $field . ' = ' . panels_var_export($panel_page->{$field}, '  ') . ";\n";
    }
  }

  // Export the contexts.
  $output .= $prefix . '$page->contexts = array()' . ";\n";
  foreach ($panel_page->contexts as $id => $info) {
    $output .= $prefix . '  $page->contexts[\'' . $id . "'] = array(\n";
    foreach ($info as $key => $value) {
      $output .= $prefix . "    '{$key}' => " . panels_var_export($value, '    ') . ",\n";
    }
    $output .= $prefix . "  );\n";
  }

  // Export the primary display
  $display = !empty($panel_page->display) ? $panel_page->display : panels_load_display($panel_page->did);
  $output .= panels_export_display($display, $prefix);
  $output .= $prefix . '$page->display = $display' . ";\n";

  // Export all secondary displays
  $output .= $prefix . '$page->displays = array()' . ";\n";
  foreach ($panel_page->displays as $id => $info) {
    $output .= $prefix . '  $page->displays[\'' . $id . "']['title'] = '" . check_plain($info['title']) . "';\n";
    $output .= $prefix . '  $page->displays[\'' . $id . "']['argument_id'] = '" . check_plain($info['argument_id']) . "';\n";
    if (!empty($info['display'])) {
      $display = $info['display'];
    }
    else {
      if (panels_page_fetch_display($panel_page, $id)) {
        $display = $panel_page->display;
      }
    }
    if (is_object($display)) {
      $output .= panels_export_display($display, $prefix . '    ');
      $output .= $prefix . '  $page->displays[\'' . $id . "']['display'] =  \$display;\n";
      unset($display);
    }
    else {
      $output .= $prefix . '  $page->displays[\'' . $id . "']['display'] =  \\NULL;\n";
    }
  }
  return $output;
}