Problem/Motivation
When creating a new entity with the default editorial workflow it would be expected the available transitions are the ones from draft (to draft or published), however it looks as though the ones from published (to draft, published, or archived) are being used.
Proposed resolution
Make sure the current state in \Drupal\content_moderation\StateTransitionValidation::getValidTransitions is correct for new entities.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2884715-16.patch | 2.66 KB | timmillwood |
| #16 | 2884715-test-only.patch | 1.86 KB | timmillwood |
Comments
Comment #2
timmillwoodIt looks as though the current state in
\Drupal\content_moderation\StateTransitionValidation::getValidTransitionsis published, when it should be draft.Comment #3
timmillwoodI think this issue was introduced in #2817835: When enabling moderation apply a relative state.
Comment #4
timmillwoodInitial fix, also need to check this works with translations.
Comment #6
timmillwoodThis patch updates the test, which was wrongly changed in #2817835: When enabling moderation apply a relative state, it also adds a test of an unsaved entity, thus the entity which would be used on a new node form.
Comment #7
sam152 commentedWe decided in #2839371: Programatically creating a published entity doesn't result in a published entity. that entities would always start their life as a draft regardless of published status, so liking this bugfix.
I think the only change I would make would be to move testing this to \Drupal\Tests\content_moderation\Kernel\InitialStateTest::testInitialState. The test methods "testArrayIteration" and "testArrayIndex" don't really fit, but we can safely update the values in that test from 'published' to 'draft'.
Otherwise, I think this is good to go.
Comment #8
timmillwoodMoved the presave node test to InitialStateTest.
Comment #9
sam152 commentedLGTM. Failing test will help committers.
Comment #10
larowlanCan we get a test-only patch here? Thanks.
Assuming we end up with red/green - looks good to me.
Comment #11
tstoecklerDoes the
->isNew()check make sense also for entities not implementingEntityPublishedInterface?Comment #12
larowlanSo in those instances (e.g. Block Content in core) it would fallback to the parent implementation, which picks the first state in the workflow.
Is that appropriate?
Comment #13
timmillwoodRight, before #2817835: When enabling moderation apply a relative state all entity types would use the first state in the workflow. The patch in that issue changed the logic to use the published state if the entity is published, but still the initial state for entity types that can't be published. This issue doesn't change that.
All this is doing is changing the initial state for new entities to draft because in content moderation we treat new entities as unpublished, where as core treats new entities as published.
Therefore I think this is the correct behaviour and should go back to RTBC.
Comment #14
tstoecklerCan't say that I fully grok all the details there, but @timmillwood being confident about its correctness works for me. Patch in general looks good and was already RTBC-ed before. Thanks for the confirmation.
Comment #15
gábor hojtsy@larowlan's request in #10 was not answered unfortunately. Should be easy to do though :)
Comment #16
timmillwoodTest only patch and a re-upload of #8.
Comment #18
timmillwoodTest only patch fails as planned, so back to RTBC.
Comment #21
gábor hojtsyDiscussed with @larowlan and he was ok as well. Thanks for the fail patch :)
Comment #22
gábor hojtsy