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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | content_copy_syntax_issues_n381876.patch | 1.02 KB | damienmckenna |
Comments
Comment #1
damienmckennaAnother 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:
but should read:
Comment #2
damienmckennaHere's a patch for the two $arr[key] issues.
Comment #3
damienmckennaForgot to update the status.
Comment #4
yched commentedCommitted. Thanks !
Comment #5
damienmckennaAwesome, thank you :-D