Closed (fixed)
Project:
Drupal core
Version:
8.3.x-dev
Component:
content_moderation.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Oct 2016 at 05:41 UTC
Updated:
13 Feb 2017 at 10:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
sam152 commentedI'm thinking something like...
Comment #3
sam152 commentedComment #4
benjy commentedThis makes sense, is status guaranteed to be a boolean field even on custom entities? Likely but maybe not always.
Also, probably need a test for this behaviour, maybe it's already tested elsewhere and this passes because the behaviour for nodes hasn't changed?
Comment #5
timmillwoodI think we should maybe think about this depending on #2810381: Add generic status field to ContentEntityBase then we can be sure that anything with the 'status' entity key has a boolean status field.
Comment #6
sam152 commentedYeah, I think if you've set the "status" entity key as something other than a boolean, that would have to be a really really edge case scenario. The generic status field looks good, but possibly not a blocker?
What is the test coverage like? Can we assumed this is covered if nodes continue to work or should it have a dedicated test? Are the moderation handlers unit testable in isolation?
Comment #7
timmillwoodWe don't have any unit tests for the moderation handlers, maybe we should.
Another good way to test this would be to add a status entity key to one of the entity_test entity types, then add to one of the kernel tests.
Comment #8
timmillwoodComment #9
sam152 commentedIt looks like #2810381: Add generic status field to ContentEntityBase could possibly be a controversial patch. Possibly #2817139: Document what the 'status' entity key should be used for on EntityTypeInterface is a bit of a middle ground that would unblock this?
Comment #10
sam152 commentedHere is a test for a generic entity. Had to introduce a revisionable and bundleable entity to entity_test.
Comment #13
sam152 commentedComment #16
sam152 commentedFixes last tests and some labels here and there.
Edit: patch file names should be switched.
Comment #18
sam152 commentedFail/pass is correct. Back to NR.
Comment #19
timmillwoodNow that #2810381: Add generic status field to ContentEntityBase has been committed I think we need to re-visit this issue.
Entity keys are not going to be a requirement for a publishing status field, therefore we can't depend on that. It'll be nice when EntityPublishedInterface is in then we can check
$entity_type instance of EntityPublishedInterface.Until then we could use entities keys, because some entity types will have them, but we'll also need another check. This check can't be for a status field because some entity types have a status field which is not used for publishing status. Maybe we can check for
setPublishedorisPublishedmethods?Comment #20
catchShould we not just get EntityPublishedInterface in and use that?
Comment #21
timmillwood@catch yes, #2789315: Create EntityPublishedInterface and use for Node and Comment is ready for review. ;)
Comment #22
amateescu commentedPostponing on #2789315: Create EntityPublishedInterface and use for Node and Comment.
Comment #23
amateescu commentedOops.
Comment #24
timmillwoodNow #2789315: Create EntityPublishedInterface and use for Node and Comment has been committed we can re-open this.
Comment #25
sam152 commentedNew approach which does away with the new entity_test entity type and adds the features to an existing type for testing. Also makes use of the new interface.
Feels so right to have this in the diff of a patch that concerns EntityPublishedInterface :)
Comment #27
sam152 commentedComment #28
timmillwoodLooks good IMHO.
Comment #29
amateescu commented\Drupal\content_moderation\Entity\Handler\NodeModerationHandler::shouldModerate()contains some logic whether we need to change the published flag or not, and this logic now applies to any entity type that implements EntityPublishedInterface, so we need to move that method up one level, use it in\Drupal\content_moderation\Entity\Handler\ModerationHandler::onPresave()and remove\Drupal\content_moderation\Entity\Handler\NodeModerationHandler::onPresave()completely.Comment #30
sam152 commentedGood catch. I've also opened #2834949: Move multilingual handling to the generic entity handler instead of making it specific to nodes. to look at moving the translation parts of the node handler into the base.
Comment #31
sam152 commentedThis patch actually moves all of the node handler logic to the base. Was required to make the tests pass.
Comment #32
amateescu commentedThat's exactly what I thought it would be needed :)
I would prefer an explicit if / else block here, but I won't hold up a commit on it.
Comment #34
sam152 commentedComment #35
sam152 commentedThe @todo is from the moved method. Opened #2834953: Clarify use of isDefaultTranslation() to determine if an entity values should be updated. for it.
Comment #36
catchCan we update this for non-deprecated method calls - setPublished()/setUnPublished()?
Otherwise looks good.
Comment #37
sam152 commentedDoes this need more testing? We have a @dataProvider that tests nodes and an entity from entity_test.
I couldn't see an instance of a param passed to setPublished in ModerationHandler.php as the feedback suggested, but there were some in the tests. Fixed.
Comment #38
amateescu commentedI think @catch posted his comment without reloading the page, so he was looking at the patch in #25 which did have
$entity->setPublished($published_state);, but it's nice that the tests are also updated now :)Comment #40
amateescu commented@Sam152, you should upload test-only patches first so the testbot doesn't kick the issue back to NW because of them ;)
Comment #41
sam152 commentedNever knew that. Good tip thanks.
Comment #42
alexpottNeeds a reroll... amazingly not that big..
Comment #43
sam152 commentedRerolled.
Comment #45
timmillwoodComment #47
sam152 commentedThink this should actually be rtbc.
Comment #48
alexpottReading this patch makes me wonder why the NodeModerationHandler exists and why the handlers are also doing form alters. Looking at \Drupal\content_moderation\Entity\Handler\ModerationHandlerInterface it is a pretty confused thing. It's methods are:
I think before committing this - which makes sense we should:
Comment #49
timmillwoodFiled the two follow up issues.
#2842040: Remove unused code from Content Moderation handlers
#2842042: Review, organise, and clean up content moderation handlers
Going to look at the test for unpublishable entities now.
Comment #50
sam152 commentedRetesting to see if this needs a reroll.
Comment #51
timmillwoodI had thought about adding a further test entity type and test bundle to test entities that implement EntityPublishedInterface and those that don't, but thought Node is testing EntityPublishedInterface, and EntityTestWithBundle can test without EntityPublishedInterface.
Comment #52
timmillwoodAdding entity_test_publish_with_bundle which implements EntityPublishedInterface so we now test three entity types.
Comment #53
timmillwoodAdding extra test coverage with block_content too.
Comment #56
sam152 commentedRan into similar fails in #13. Perhaps the same fix will work here. If not, ignore.
Comment #57
sam152 commentedComment #58
amateescu commentedSome high-level overview for now, I'm going to go into nitpick mode after the big questions are answered :)
This looks suspicious, how can a entity type be moderated without being a publishable entity type?
Since we now define a new test entity type class, do we still need to test this one as well?
Does this entity type really need to have bundles?
Comment #59
amateescu commentedDiscussed with @timmillwood and my main concern from #58 is actually: why do have to test with entity types that store bundles in config (i.e. a config entity type). He's going to look into that now.
Comment #60
timmillwoodAfter looking into this today it's not going to be possible to use content moderation without a config bundle until we resolve #2799785: Entity types with non-config bundles can not be moderated. Also I think we do need to test entity types that can be published and entity types that can't be published until we decide on #2842692: Warn users before enabling moderation on an entity type that can't be (un)published.
Comment #61
sam152 commentedYep, the point of the three entity types were:
It would be nice to not have any more blockers for this issue, but #2799785: Entity types with non-config bundles can not be moderated looks like it's making good progress, if we want to keep entity_test free of config based bundles.
If other concerns come up around putting CM-centric stuff in entity_test, we could possibly create exactly the tailored entity types we need in ./content_moderation/tests/modules, which might also allow some cleanup on the entity definition alterations in the test code. Just a thought for down the track.
Comment #62
timmillwoodAfter some thought about this handlers, do we really need onPresave in them? Why don't we just put this code in \Drupal\content_moderation\EntityOperations::entityPresave?
Comment #63
timmillwoodSimplifying the patch now we don't need bundles for testing.
Comment #64
timmillwoodI don't think we really need the presave in the handler, lets move it out.
Also removing an unused schema from a previous version of the patch.
Comment #65
sam152 commented+1 to #63. I think #64 should be another discussion. Just need the schema removal from #64.
I probably can't RTBC this, but I think it's ready.
Comment #66
timmillwoodWe can discuss removing the presave (and maybe the whole handler) in #2842042: Review, organise, and clean up content moderation handlers.
Interdiff based on #63.
Comment #67
amateescu commentedI reviewed this patch a few times already, and the latest one looks great!
Comment #68
alexpottI'm not sure about this logic change. Before we were always calling $entity->setNewRevision(TRUE) for non nodes and now we are not.
I think this is a pretty complex structure to grok and it makes finding code usages unnecessarily hard.
How about (if you want to keep the ternary)
Or just use a regular
if.Comment #69
timmillwoodComment #70
amateescu commentedWe should probably combine these 'if's :)
Comment #71
timmillwoodGood point, merged publishing interface check into shouldModerate().
Comment #72
sam152 commentedI think we're missing the check altogether now? Otherwise LGTM.
Comment #73
timmillwoodThe check has moved to shouldModerate()
Comment #74
sam152 commentedWhat if the call to isDefaultTranslation is TRUE?
Comment #76
timmillwoodRemoved shouldModerate(), this seems to work now.
This will also resolve #2834953: Clarify use of isDefaultTranslation() to determine if an entity values should be updated..
Comment #77
sam152 commentedInterdiff LGTM, the name shouldModerate was fairly ambiguous, so glad to see it go.
Comment #78
alexpottFunnily enough I think the idea that ContentModeration should only work on entity types that implement EntityPublishedInterface makes way more sense than the current requirement for revisions.
Anyhow this is a step in the right direction that makes it easier to use content moderation on more entity types without customisation.
Committed d55b420 and pushed to 8.3.x. Thanks!
Fixed some code style stuff on commit.
Comment #82
timmillwood#2846830: Add changelog for Drupal 8.3.0