Problem/Motivation
Precursor to #2830581: Fix ContentModeration workflow type to calculate correct dependencies. As a result of @xjm's reviews we realised that \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::appliesToEntityTypeAndBundle()
and \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::getBundlesForEntityType()
can be made more consistent
Proposed resolution
Change \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::getBundlesForEntityType()
to not produce a PHP warning when getting bundle info for an entity not under workflow.
Change \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::appliesToEntityTypeAndBundle()
to use the updated method.
Remaining tasks
User interface changes
None
API changes
\Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::appliesToEntityTypeAndBundle()
returns an empty array for entity types that are not under workflow.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#10 | 2850341-10.patch | 5.87 KB | alexpott |
#10 | 2-10-interdiff.txt | 4.81 KB | alexpott |
#2 | 2850341-2.patch | 4.58 KB | alexpott |
Comments
Comment #2
alexpottThis is a major task because it blocks #2830581: Fix ContentModeration workflow type to calculate correct dependencies
Comment #3
alexpottComment #4
xjmCrossposting my review on this change from the other issue:
So TLDR, this change makes the DX more friendly and there are precedents elsewhere in core for simply returning an empty array if the entity type or entity/bundle combo are not relevant in context.
Comment #5
xjmAlso just tagging for clarity. @timmillwood also implicitly signed off on this change from the other issue but would still be good to have an explicit signoff on this as a design behavior. Thanks!
Comment #6
timmillwoodLgtm
Comment #7
timmillwoodGiving explicit sign off.
As @xjm said, returning an empty array is a familiar approach in core.
Comment #8
xjm+1 for these explicit tests of the conditions, especially the empty cases.
Small improvement I suggest:
Comment #9
xjmWe can also document clearly that this API does not validate the entity type/bundle relationship or even that they exist, just whether they are configured for the workflow and the list will be empty regardless of why they don't.
I debated whether to add a CR but I don't think we need one since it's changing a return value from a bad, undocumented NULL + warning to an expected empty value.
Comment #10
alexpottMaking the changes suggested by @xjm and also adding missing docs I noticed on one of the methods we're changing and adding tests for.
Comment #11
timmillwoodInterdiff seems to cover everything.
Comment #14
xjmGreat! This full patch, with explicit docs and tests for the related methods, makes the API make a lot more sense to me.
Since this is an API hardening for an alpha experimental module, I've also backported this change to 8.3.x. Thanks!
Comment #15
xjmSlightly overeager I guess: #2850592: Typos in ContentModertaionWorkflowTypeApiTest
Comment #16
timmillwoodOops guess I read what I want to see.