When importing an exported node with attached display (export_display) importation will not be complete since import callback will eval on $code_string and export_display php code will be truncated. So no panels display data will be imported.

Example:

exported code as export_display attribute as the following:

 'node_export_drupal_version' => '7',
 'export_display' => "$display = new panels_display();\n$display->layout = 'flexible:...

during node_export_drupal_import($code_string) execution nodes array will be obtained by calling eval on above:

$nodes = eval('return ' . $code_string . ';');

and export_display will now be:

 'node_export_drupal_version' => '7',
 'export_display' => "  = new panels_display(); = 'flexible:...

escaping the $code_string seems to work, but seems more an ugly hack than a solution:

$code_string = str_replace('$', '\$', $code_string);

Comments

danielb’s picture

Title: Import fails for exported panels nodes » Imports fail when node data contains PHP code.
fizk’s picture

Title: Imports fail when node data contains PHP code. » Imports fail when node data contains PHP or Javascript code.

I ran into this issue as well, although I'm using Javascript instead of PHP in $code_string.

My workaround was to implement hook_node_export_decode_alter():

/**
 * Implements hook_node_export_decode_alter().
 */
function mymodule_node_export_decode_alter(&$code_string) {
  // Escape $variables in PHP/Javascript code.
  preg_match('#<script>(.+)</script>#Usm', $code_string, $script);
  if ($script) {
    $replacement = preg_replace('#\$([a-zA-Z])#', '\\\\$${1}', $script[1]);
    $code_string = str_replace($script[1], $replacement, $code_string);
  }
}