You are here

function panels_page_export in Panels 5.2

Same name and namespace in other branches
  1. 6.2 panels_page/panels_page.write.inc \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_edit_export in panels_page/panels_page.admin.inc
Page callback to export a panel page to PHP code.
panels_page_panels_exportables in panels_page/panels_page.module
Implementation of hook_panels_exportables().

File

panels_page/panels_page.module, line 1057
panels_page.module

Code

function panels_page_export($panel_page, $prefix = '') {
  $output = '';
  $fields = panels_page_fields();
  $output .= $prefix . '$page = new stdClass()' . ";\n";
  $output .= $prefix . '$page->pid = \'new\'' . ";\n";
  foreach (array_keys($fields) as $field) {
    if (!isset($panel_page->{$field}) || in_array($field, array(
      'displays',
      'contexts',
      'display',
    ))) {
      continue;
    }
    $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 $did => $info) {
    $output .= $prefix . '  $page->displays[\'' . $did . "']['title'] = '" . check_plain($info['title']) . "';\n";
    $output .= $prefix . '  $page->displays[\'' . $did . "']['argument_id'] = '" . check_plain($info['argument_id']) . "';\n";
    $display = !empty($info['display']) ? $info['display'] : panels_load_display($info['did']);
    $output .= panels_export_display($display, $prefix . '    ');
    $output .= $prefix . '  $page->displays[\'' . $did . "']['display'] =  \$display;\n";
  }
  return $output;
}