There are syntax issues in the data output from both 5.x-1.x and 6.x-2.x:

* The main content arrays are printed as $content[key] instead of the correct $content['key'] and thus will give a warning when error_reporting() is set to E_ALL. See the PHP manual arrays page and scroll down to "Why is $foo[bar] wrong?" In 6.x-2.1 this the output is incorrectly created on line 609:

      $string .= "\$content[$form_type]  = ". var_export((array) $form, TRUE) .";\n";

This should read:

      $string .= "\$content['$form_type']  = ". var_export((array) $form, TRUE) .";\n";

A simple example might be:

$content[type]  = array (
  'name' => 'Webform',
  'type' => 'webform',
  'description' => '',
  'title_label' => 'Title',
  'body_label' => 'Body',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => false,
    'sticky' => false,
    'revision' => false,
  ),
  'language_content_type' => '0',
  'show_preview_changes' => 1,
  'nodewords' => 1,
  'scheduler' => 1,
  'scheduler_touch' => 1,
  'old_type' => 'webform',
  'orig_type' => 'webform',
  'module' => 'webform',
  'custom' => '0',
  'modified' => '1',
  'locked' => '1',
  'reset' => 'Reset to defaults',
  'location_addanother' => 0,
);

This should be output as:

$content['type']  = array (
  'name' => 'Webform',
  'type' => 'webform',
  'description' => '',
  'title_label' => 'Title',
  'body_label' => 'Body',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => false,
    'sticky' => false,
    'revision' => false,
  ),
  'language_content_type' => '0',
  'show_preview_changes' => 1,
  'nodewords' => 1,
  'scheduler' => 1,
  'scheduler_touch' => 1,
  'old_type' => 'webform',
  'orig_type' => 'webform',
  'module' => 'webform',
  'custom' => '0',
  'modified' => '1',
  'locked' => '1',
  'reset' => 'Reset to defaults',
  'location_addanother' => 0,
);

* A smaller issue, but the fields export block seems a little trigger happy with outputting unneeded array numeric indexes, especially with arrays starting at 0. The main field block ends up looking something like this:

$content[fields]  = array (
  0 => 
  array (/* field data */),
);

Given that arrays automatically start at zero and increment by 1, why not just do this?

$content[fields]  = array (
  array (/* field data */),
);

Damien

Comments

damienmckenna’s picture

Another minor syntax issue:
* The Drupal coding styleguide states that boolean values should be written in uppercase, i.e. "TRUE" and "FALSE". This comes direct from var_export but it may be worth considering doing a str_replace() to change " => true," to " => TRUE," and " => false," to " => FALSE,".

Another occurrence of the $arr[key] syntax issue:
* content_copy.module, line 270, it reads:

    $output .= "\$content[extra]  = ". var_export((array) $extra, TRUE) .";\n";

but should read:

    $output .= "\$content['extra']  = ". var_export((array) $extra, TRUE) .";\n";
damienmckenna’s picture

StatusFileSize
new1.02 KB

Here's a patch for the two $arr[key] issues.

damienmckenna’s picture

Status: Active » Needs review

Forgot to update the status.

yched’s picture

Status: Needs review » Fixed

Committed. Thanks !

damienmckenna’s picture

Awesome, thank you :-D

Status: Fixed » Closed (fixed)
Issue tags: -Novice, -syntax error

Automatically closed -- issue fixed for 2 weeks with no activity.