Commit bd28b217 authored by webchick's avatar webchick

Issue #2221789 by Schoonzie, marthinal, sidharthap | Berdir: Not possible to...

Issue #2221789 by Schoonzie, marthinal, sidharthap | Berdir: Not possible to disable 'Save new revision' when enabled by default.
parent 58f31ac2
......@@ -349,12 +349,15 @@ public function submit(array $form, array &$form_state) {
$node = parent::submit($form, $form_state);
// Save as a new revision if requested to do so.
if (!empty($form_state['values']['revision'])) {
if (!empty($form_state['values']['revision']) && $form_state['values']['revision'] != FALSE) {
$node->setNewRevision();
// If a new revision is created, save the current user as revision author.
$node->setRevisionCreationTime(REQUEST_TIME);
$node->setRevisionAuthorId(\Drupal::currentUser()->id());
}
else {
$node->setNewRevision(FALSE);
}
$node->validated = TRUE;
foreach (\Drupal::moduleHandler()->getImplementations('node_submit') as $module) {
......
<?php
/**
* @file
* Contains \Drupal\node\Tests\NodeRevisionsUiTest.
*/
namespace Drupal\node\Tests;
/**
* Tests the node revision functionality.
*/
class NodeRevisionsUiTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Node revisions UI test',
'description' => 'Checks the UI for controlling node revision behavior.',
'group' => 'Node',
);
}
/**
* {@inheritdoc}
*/
function setUp() {
parent::setUp();
// Create and log in user.
$web_user = $this->drupalCreateUser(
array(
'administer nodes',
'edit any page content'
)
);
$this->drupalLogin($web_user);
}
/**
* Checks that unchecking 'Create new revision' works when editing a node.
*/
function testNodeFormSaveWithoutRevision() {
// Set page revision setting 'create new revision'. This will mean new
// revisions are created by default when the node is edited.
$type = entity_load('node_type', 'page');
$type->settings['node']['options']['revision'] = TRUE;
$type->save();
// Create the node.
$node = $this->drupalCreateNode();
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Uncheck the create new revision checkbox and save the node.
$edit = array('revision' => FALSE);
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
// Load the node again and check the revision is the same as before.
$node_revision = node_load($node->id(), TRUE);
$this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created.");
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Submit the form without changing the checkbox.
$edit = array();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
// Load the node again and check the revision is different from before.
$node_revision = node_load($node->id(), TRUE);
$this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created.");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment