Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
3f6a61e7
Verified
Commit
3f6a61e7
authored
May 13, 2022
by
alexpott
Browse files
Issue
#3252100
by amateescu, catch, Tim Bozeman: Set revision_default when publishing
(cherry picked from commit
29856d74
)
parent
00991b9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
View file @
3f6a61e7
...
...
@@ -708,10 +708,12 @@ protected function doSave($id, EntityInterface $entity) {
$this
->
populateAffectedRevisionTranslations
(
$entity
);
// Populate the "revision_default" flag. We skip this when we are resaving
// the revision because this is only allowed for default revisions, and
// these cannot be made non-default.
if
(
$this
->
entityType
->
isRevisionable
()
&&
$entity
->
isNewRevision
())
{
// Populate the "revision_default" flag. Skip this when we are resaving
// the revision, and the flag is set to FALSE, since it is not possible to
// set a previously default revision to non-default. However, setting a
// previously non-default revision to default is allowed for advanced
// use-cases.
if
(
$this
->
entityType
->
isRevisionable
()
&&
(
$entity
->
isNewRevision
()
||
$entity
->
isDefaultRevision
()))
{
$revision_default_key
=
$this
->
entityType
->
getRevisionMetadataKey
(
'revision_default'
);
$entity
->
set
(
$revision_default_key
,
$entity
->
isDefaultRevision
());
}
...
...
core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php
View file @
3f6a61e7
...
...
@@ -356,6 +356,13 @@ public function testWorkspaces() {
$this
->
assertWorkspaceStatus
(
$test_scenarios
[
'push_stage_to_live'
],
'node'
);
$this
->
assertWorkspaceAssociation
(
$expected_workspace_association
[
'push_stage_to_live'
],
'node'
);
// Check that all the revisions that were published to 'Live' were also
// marked as default revisions in their revision metadata field.
$published_revisions
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
loadMultipleRevisions
(
array_keys
(
$expected
[
'node'
]));
foreach
(
$published_revisions
as
$published_revision
)
{
$this
->
assertTrue
(
$published_revision
->
wasDefaultRevision
());
}
// Check that there are no more revisions to push.
$this
->
assertEmpty
(
$workspace_publisher
->
getDifferringRevisionIdsOnSource
());
}
...
...
core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php
View file @
3f6a61e7
...
...
@@ -261,4 +261,32 @@ public function testIsLatestAffectedRevisionTranslation() {
$this
->
assertTrue
(
$en_revision
->
isLatestTranslationAffectedRevision
());
}
/**
* Tests the automatic handling of the "revision_default" flag.
*
* @covers \Drupal\Core\Entity\ContentEntityStorageBase::doSave
*/
public
function
testDefaultRevisionFlag
()
{
// Create a basic EntityTestMulRev entity and save it.
$entity
=
EntityTestMulRev
::
create
();
$entity
->
save
();
$this
->
assertTrue
(
$entity
->
wasDefaultRevision
());
// Create a new default revision.
$entity
->
setNewRevision
(
TRUE
);
$entity
->
save
();
$this
->
assertTrue
(
$entity
->
wasDefaultRevision
());
// Create a new non-default revision.
$entity
->
setNewRevision
(
TRUE
);
$entity
->
isDefaultRevision
(
FALSE
);
$entity
->
save
();
$this
->
assertFalse
(
$entity
->
wasDefaultRevision
());
// Turn the previous non-default revision into a default revision.
$entity
->
isDefaultRevision
(
TRUE
);
$entity
->
save
();
$this
->
assertTrue
(
$entity
->
wasDefaultRevision
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment