summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2015-03-30 16:49:06 -0400
committerDavid Rothstein <drothstein@gmail.com>2015-03-30 16:49:06 -0400
commitc0f687ed41e2bd171b422485ef2362eddb2ce918 (patch)
tree9c6403978a4ae94d70abe57ab3955274b679dbc4 /modules
parentd67fd28f14c9a5e4e596a75749b4e6fb4c80da3d (diff)
downloadbrdo-c0f687ed41e2bd171b422485ef2362eddb2ce918.tar.gz
brdo-c0f687ed41e2bd171b422485ef2362eddb2ce918.tar.bz2
Issue #2001308 by stefan.r, David_Rothstein, marthinal, helmo: Node preview removes file values from node edit form for non-displayed items
Diffstat (limited to 'modules')
-rw-r--r--modules/file/tests/file.test12
-rw-r--r--modules/node/node.pages.inc35
2 files changed, 31 insertions, 16 deletions
diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test
index 0f6a578d9..e2c5737f4 100644
--- a/modules/file/tests/file.test
+++ b/modules/file/tests/file.test
@@ -877,6 +877,7 @@ class FileFieldDisplayTestCase extends FileFieldTestCase {
$field_settings = array(
'display_field' => '1',
'display_default' => '1',
+ 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
$instance_settings = array(
'description_field' => '1',
@@ -917,6 +918,17 @@ class FileFieldDisplayTestCase extends FileFieldTestCase {
$this->assertNoRaw($default_output, 'Field is hidden when "display" option is unchecked.');
+ // Test that fields appear as expected during the preview.
+ // Add a second file.
+ $name = 'files[' . $field_name . '_' . LANGUAGE_NONE . '_1]';
+ $edit[$name] = drupal_realpath($test_file->uri);
+
+ // Uncheck the display checkboxes and go to the preview.
+ $edit[$field_name . '[' . LANGUAGE_NONE . '][0][display]'] = FALSE;
+ $edit[$field_name . '[' . LANGUAGE_NONE . '][1][display]'] = FALSE;
+ $this->drupalPost('node/' . $nid . '/edit', $edit, t('Preview'));
+ $this->assertRaw($field_name . '[' . LANGUAGE_NONE . '][0][display]', 'First file appears as expected.');
+ $this->assertRaw($field_name . '[' . LANGUAGE_NONE . '][1][display]', 'Second file appears as expected.');
}
}
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index 626746362..cc3908e3c 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -371,35 +371,38 @@ function node_form_build_preview($form, &$form_state) {
* @see node_form_build_preview()
*/
function node_preview($node) {
- if (node_access('create', $node) || node_access('update', $node)) {
- _field_invoke_multiple('load', 'node', array($node->nid => $node));
+ // Clone the node before previewing it to prevent the node itself from being
+ // modified.
+ $cloned_node = clone $node;
+ if (node_access('create', $cloned_node) || node_access('update', $cloned_node)) {
+ _field_invoke_multiple('load', 'node', array($cloned_node->nid => $cloned_node));
// Load the user's name when needed.
- if (isset($node->name)) {
+ if (isset($cloned_node->name)) {
// The use of isset() is mandatory in the context of user IDs, because
// user ID 0 denotes the anonymous user.
- if ($user = user_load_by_name($node->name)) {
- $node->uid = $user->uid;
- $node->picture = $user->picture;
+ if ($user = user_load_by_name($cloned_node->name)) {
+ $cloned_node->uid = $user->uid;
+ $cloned_node->picture = $user->picture;
}
else {
- $node->uid = 0; // anonymous user
+ $cloned_node->uid = 0; // anonymous user
}
}
- elseif ($node->uid) {
- $user = user_load($node->uid);
- $node->name = $user->name;
- $node->picture = $user->picture;
+ elseif ($cloned_node->uid) {
+ $user = user_load($cloned_node->uid);
+ $cloned_node->name = $user->name;
+ $cloned_node->picture = $user->picture;
}
- $node->changed = REQUEST_TIME;
- $nodes = array($node->nid => $node);
+ $cloned_node->changed = REQUEST_TIME;
+ $nodes = array($cloned_node->nid => $cloned_node);
field_attach_prepare_view('node', $nodes, 'full');
// Display a preview of the node.
if (!form_get_errors()) {
- $node->in_preview = TRUE;
- $output = theme('node_preview', array('node' => $node));
- unset($node->in_preview);
+ $cloned_node->in_preview = TRUE;
+ $output = theme('node_preview', array('node' => $cloned_node));
+ unset($cloned_node->in_preview);
}
drupal_set_title(t('Preview'), PASS_THROUGH);