Updated: Comment #N
Problem/Motivation
Discovered in #2211949: Support keeping new revision id for migrate.
The form controller for nodes and custom blocks now initially call setIsNewRevision() to set the default value for the checkbox.
Later on, it is called again in prepareEntity() but only if the checkbox is checked. Which made sense before the initial call existed, but now we need to explicitly disable it instead when not checked.
Fairly easy to reproduce:
1. Make sure the save new revision checkbox in the node type settings is enabled.
2. Create a node
3. Edit now, disable checkbox, save.
Expected result: No revision has been saved, no revisions tab visible.
Actual result: Two revisions exist now.
Proposed resolution
Change the calls to pass the value of the checkbox to the function.
Remaining tasks
Fix needs to be written and a test needs to be created, that test do the steps above. Maybe a new method in NodeRevisionsTest?
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | interdiff-2221789-6-16.txt | 5.56 KB | Schoonzie |
| #17 | 2221789-17-complete.patch | 3.93 KB | Schoonzie |
| #16 | 2221789-16-tests.patch | 2.92 KB | Schoonzie |
| #12 | 2221789-12-complete.patch | 3.93 KB | Schoonzie |
| #8 | 2221789-8-complete.patch | 4 KB | Schoonzie |
Comments
Comment #1
sidharthapI checked the node module and found this.
// Always use the default revision setting.
$node->setNewRevision(!empty($this->settings['options']['revision']));
Here i am attaching the patch to remove this line. I tested it on my local removing this line and it resolves the issue.
Comment #2
berdirThanks, but this is not the right fix. that call is required for the new revision checkbox to be enabled or not based on the node tape settings.
Comment #3
sidharthapThanks @Berdir,
how about to place a else condition here if check box value is null ?
public function submit(array $form, array &$form_state) {
// Build the node object from the submitted values.
$node = parent::submit($form, $form_state);
// Save as a new revision if requested to do so.
if (!empty($form_state['values']['revision'])) {
$node->setNewRevision();
.........
}
else {
$node->setNewRevision(FALSE);
}
Comment #4
berdirYes for example, or just $node->setNewRevision(!empty($form_state['values']['revision']));
Comment #5
marthinal commentedWe need to verify if the checkbox is not checked (FALSE). Let's try this.
Comment #6
Schoonzie commentedPatch #5 works fixes the issue for me. I'll have a look at writing a test now.
Comment #7
Schoonzie commentedTest attached. This test sets the 'revision' settings for page content types to true and creates a new node. It then loads the node edit form and asserts the 'create new revision' checkbox is checked. Then it submits the node edit form with the 'Create new revision' checkbox unchecked asserts that a revision is not created.
This fails without the patch in #5.
Comment #8
Schoonzie commentedAttached patch with fix by marthinal and test by me.
Comment #10
berdirTests and fix looks good, thanks!
Just a bunch of coding style/naming things to fix and then this is ready to go :)
Should be Contains of \Drupal\... instead of Definition of...
Should we name this NodeRevisionUiTest or so, to clarify that we're testing the UI unlike the other revision tests? I think it's better to not make this too specific about creating new revisions, as we're actually testing that we're not creating one and might add more tests later on.
Seem unused, so can be removed.
Same here, then I'd say name is something "Node revision UI", or maybe Node revision form? class should in that case also be Form instead of Ui.
The description can be shorter, we might also add more test method to this later for other examples, so make it a bit more generic. "Checks the UI for controlling node revision behavior." or so?
@inheritdoc should also be added to setUp() and getInfo() now.
I think this on by default but it makes sense to ensure that anyway. However, we should use the entity API to change a config entity:
I think...
Create... instead of create...
Comment #11
Schoonzie commentedThanks for the feedback! I will update the test class and redo the patch.
Comment #12
Schoonzie commentedI have updated the test class based on those suggestions and attached a patch which includes marthinal's fix.
There are some UI tests in NodeRevisionsTest but that is testing that the permissions around revisions work so I think this is OK to be in it's own class. Let me know if you think otherwise.
Comment #13
berdirThanks, looks good. Only nitpick that I was able to find is the missing leading \ in the @file docblock, it should be "Contains \Drupal\node\Tests\NodeRevisionsUiTest".
Also, When updating a patch based on a review, it is very helpful to provide an interdiff, see https://drupal.org/documentation/git/interdiff. That makes it easier for me to verify the changes you made since the last patch.
Comment #14
marthinal commented@Schoonzie Normally we add 2 patches.
One with only the test (that should fail).
And the other that fixes this fail.
I didn't try this test but I tell you for the future :)
Many thanks for your help.
Comment #15
berdir@marthinal: Yep. There's a patch with only the test in #7, but it would probably make sense to have the final patch as a test-only patch too, to proof that it still fails, but we didn't make any functional changes on the test since then I think.
Comment #16
Schoonzie commentedThanks for the feedback again. Hopefully this is the last round.
Attached is a patch with just the test. This should fail.
I have also attached an interdiff of this patch and the patch in #7, however because the file was renamed it is not really helpful.
Comment #17
Schoonzie commentedAnd here is the complete patch with the fix and the tests. This should pass.
Is this type of patch needed / useful?
Comment #18
Schoonzie commentedOops, here is the interdiff I mentioned in #16
Comment #20
heathergaye commentedTested patch at #17, applies, works as described.
Comment #21
webchickNice catch, and great to have some expanded test coverage for this!
Committed and pushed to 8.x. Thanks!