Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Steps to reproduce
- Enable
content_moderation
- Assign a workflow to a node bundle
- Create a new node view and add a "Moderation state" field
- Enable aggregation and execute the view
Result:
Drupal\Core\Entity\Sql\SqlContentEntityStorageException: Column information not available for the 'moderation_state' field. in Drupal\Core\Entity\Sql\DefaultTableMapping->getFieldColumnName() (line 430 of core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php).
Proposed resolution
As a workaround the deprecated moderation state relationship can still be used with a view that has aggregation enabled.
Comment | File | Size | Author |
---|---|---|---|
#23 | Moderation State Aggregate Settings.png | 89.29 KB | tyler.hastain |
#17 | interdiff-3135409-16_17.txt | 602 bytes | Anchal_gupta |
#17 | 3135409-17.patch | 3.59 KB | Anchal_gupta |
| |||
#16 | 3135409-content-moderation-aggregation-16.patch | 3.59 KB | Fernly |
#14 | 3135409-content-moderation-aggregation-14.patch | 2.68 KB | segi |
Comments
Comment #2
grota CreditAttribution: grota at SparkFabrik commentedComment #4
aditya.ghan CreditAttribution: aditya.ghan commentedHello,
Facing the same issue. Is there any associated drupal issue link for this issue?
Thanks!
Adi
Comment #5
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedThis still happens in 9.0.x but the workaround no longer applies as the relationship has been removed by the looks of it.
Comment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis fixes the issue for me, simply by switching off aggregation and forcing it as
FALSE
during::query
.I can't think of a specific use case, but would it be valid to do aggregation on the moderation state field, through the join to the content_moderation_state entity? Ideally the computed field would behave as close to a normal field as possible, which would mean supporting this, but that doesn't look very easy. Maybe opened as a follow-up feature request?
Comment #7
esod CreditAttribution: esod at Memorial Sloan Kettering Cancer Center commentedI confirm that we also ran into this problem. The patch fixes the problem. The patch applies cleanly to Drupal 8.8.8.
The view where we ran into this problem shows the editor all the nodes they have submitted moderation state changes on, regardless of if they are the
Revision user
or not.The scenario is like this:
Request publish
but cannot publish the node.Published
.Published
.The views query requires GROUP BY because otherwise the results of the views query will include all the node revisions from that user, thus duplicates. Thus the need for aggregation in the view.
Comment #8
holist CreditAttribution: holist at Siili Solutions commentedThis looked promising but with my use case the issue behind this is actually bigger. Applying the patch from #6 does not allow sorting by moderation states when aggregation is on, as forcing GROUP BY off on the moderation state makes the field unusable in ORDER BY.
While the exception is thrown when the grouping on moderation state is set to "value", keeping grouping at "entity id" makes the view work just without sorting by moderation state available. Obviously this can lead to unwanted results in some cases where revisions would matter.
I'm not quite sure where to start looking for a proper solution, as the
ensureMyTable
method to me looks like it does the join as I would expect, but theclickSort
method seems not to make use of it.Marking as Needs work as I kind of would like to push for a more elegant solution as from my perspective this is now broken with the old relationship removed in 9.0.
Comment #9
holist CreditAttribution: holist at Siili Solutions commentedI had a simple workaround pointed out by a colleague. We added a hook_query_TAG_alter() that contains the following:
This effectively adds the content moderation state field to GROUP BY when it is in ORDER BY, giving MySQL what it wanted. Does not by the way work if DISTINCT is set.
I don't think having to do that kind of alteration is really the correct way to make this work, but maybe this could point for a better solution?
Comment #11
mdupontIt seems it is still an issue in latest Drupal version, bumping to 9.3.x-dev.
Comment #14
segi CreditAttribution: segi at Cheppers commentedI think I found a better solution. I have tested it works with aggregation and shorting as well.
Comment #16
Fernly CreditAttribution: Fernly at Dropsolid for District09 commentedThe patch in #14 does not work if the view shows content types with and without workflow enabled. The following error is thrown:
Fatal error: Uncaught Error: Call to a member function getTypePlugin() on null in .../web/core/modules/content_moderation/src/Plugin/Field/FieldFormatter/ContentModerationStateFormatter.php:64
Rerolled the patch of #14 to fix this issue. Patched against 9.5.x.
Comment #17
Anchal_gupta CreditAttribution: Anchal_gupta at Material for Drupal India Association commentedI have fix cs error. Please review it
Comment #18
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Tested this on 10.1.x but I receive
In the logs and the patch in #17 does not fix the issue I'm seeing.
Tagging for tests and an issue summary update.
Thanks
Comment #20
jdleonard#17 applied to 10.1.3 and allowed my view with aggregation to work with a Moderation State field.
Setting to Needs Review as there are no steps to reproduce the error described in #18 and this is working for me.
Comment #21
smustgrave CreditAttribution: smustgrave at Mobomo commentedIssue summary update and tests will still be needed.
Comment #22
david-urban CreditAttribution: david-urban as a volunteer commentedI have just tested with 10.2.2 and the #17 patch seems to be working.
Comment #23
tyler.hastain CreditAttribution: tyler.hastain commentedAdded patch 17 for Drupal 10.2.4. It only fixes the issue if the aggregation setting for the moderation state is set to aggregate on the Entity ID instead of the Value. (See attached screenshot for more information.)
Comment #24
maskedjellybeanThank you for this. #17 worked for me in Drupal 10.2.3.