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/Motivation
There's no views sort handler for sorting on the moderation state field. In #2862041: Provide useful Views filters for Content Moderation State fields, a filter handler was added for filtering on moderation state. It would be useful to have this so results could be ordered by their current moderation state.
Steps to reproduce this:
- Install content moderation.
- Go to Content > Moderated content.
- Click on the "Moderation state" column.
- Exception should appear.
Proposed resolution
Add the appropriate handlers to make sorting work.
Remaining tasks
Review patch.
User interface changes
Fixes exception that bubbles up to the UI.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#67 | 2953331-67.patch | 36.52 KB | alexpott |
#67 | 65-67-interdiff.txt | 1.99 KB | alexpott |
#65 | 2953331-65.patch | 36.37 KB | Manuel Garcia |
#65 | interdiff-2953331-56-65.txt | 2.44 KB | Manuel Garcia |
#59 | 2953331-56.patch | 37.99 KB | Sam152 |
Comments
Comment #2
anish.a CreditAttribution: anish.a at Accenture commentedAssuming this is the issue. There is no table sorter for headers.
Comment #3
bkosborneThe issue is that there's no underlying support for any view to sort by the moderation state. RE: your screenshot, indeed, none of those headers are click-sortable, but that's not directly related to this issue.
Comment #4
steven.wichers CreditAttribution: steven.wichers as a volunteer commentedWorkaround: Add a "Content moderation state" relationship to your view. Add a "Moderation state" field that uses the relationship. Enable the field overwrite functionality and use the output for the original moderation state field. Hide the original moderation state field.
This will give you a sortable moderation state column that uses the correct display label.
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedFinally got around to addressing this. This patch:
Comment #7
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedFixing docblock.
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe patch looks great to me!
I was a bit unsure about this part, but we're only using the
entityTypeManager
property internally inModerationStateJoinViewsHandlerTrait
, so maybe it's ok to do it like this.Comment #9
alexpottThis property is declared dynamically so it'll be public. We need to define it on this class - or somehow fix EntityField to use the specific entity manager services - which feels unlikely in this issue.
Comment #10
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for the review, good catch.
Comment #11
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedJust dropping by here out of curiosity, and because I think its a good idea :)
Patch is looking great, my only concern is this change:
Does this mean we need an upgrade path for existing views?
Comment #12
jibranYes!
Comment #13
jibranTagging.
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe mismatch here makes me want to have the proper entity type service even more :/
Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedYeah, I agree. Lets inject the proper service here in addition to looking into #11.
Comment #17
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding the upgrade path and tests for that.
Comment #18
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRealising why this view wasn't in the fixture originally: it was introduced in 8.5. To ensure the integrity of the 8.4 fixture, we should add this is another fixture.
Updating.
Comment #20
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAddressing #14.
Comment #21
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe latest patch looks very good, I spotted just a couple of minor things:
That's not necessarily true, for example the JSON entity storage could store the whole entity data in a single table column, so we should do to the right thing and get the column name from the table mapping :)
Let's add an empty line between these, and append
()
to the post update function name :)Comment #22
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedGood catch, thanks for the review.
Comment #23
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAddressing feedback from #21.
Comment #24
jibranThis looks ready to me.
Comment #25
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented+1, looks good to me as well.
Comment #26
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedThanks @Sam152 - upgrade path & tests look good to me, RTBC++
Comment #27
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented@jibran pinged me and made me aware of #2810485: Allow more maintainers to grant credit. He answered some questions for me in slack when I was writing the upgrade path, so granting request for credit here. Adding @amateescu, @Manuel Garcia and @alexpott for reviews while I'm at it.
Comment #29
larowlanNo longer applies :(
Comment #30
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRerolling
Comment #32
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAnother reroll, this time with less syntax errors guaranteed!
Comment #34
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding a secondary sort criteria of the langcode. I think the two different language revisions were sorting inconsistently locally and on the bot when they had the same state name.
Comment #36
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedHm, it's possible views doesn't support secondary sort criteria mixed with exposed input. This will possibly make testing this in a flexible way tricky.
Comment #37
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAfter digging into this, I believe this is the only way to maintain the same level of test coverage with consistent builds.
Comment #38
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis was already RTBC before a reroll and the interdiff in #37 in case anyone is interested in reviewing the changes since then.
Comment #39
sorabh.v6Hi @Sam512,
I applied the patch in #37 and now I am able to sort the content using the state but when I did the
drush updb
, I got this error -Comment #40
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedPlease test this on 8.7.x HEAD if you are reviewing the issue. This patch hasn't been backported to previous versions, so if you're running 8.6 or 8.5, you'll manually have to backport this if you are evaluating it.
It's likely in your case the
ConfigEntityUpdater
wasn'tuse
'd at the top of the file, since it was probably included by another update hook that hasn't made it into the release you are running.Comment #41
sorabh.v6Ahh! yes I was using that patch on 8.6. Thanks, adding use statement made it work. I believe that was the only missing thing for 8.6 compatibility, if not please tell me I can work on patch for 8.6 backport.
Comment #42
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedFWIW, RTBC++ on #37
Comment #43
Wim LeersI reviewed #2862041: Provide useful Views filters for Content Moderation State fields for cacheability, so I figured I'd do the same here.
👍 This inherits
\Drupal\Core\Plugin\ContextAwarePluginBase::getCacheTags()
, which inspects the used contexts to determine the cache tags.EntityField
is known to handle cache tags correctly, which means this should too.🤔 It would be nice if this were to verify that modifying the moderation state of either node would invalidate the cached response. (And that both previous requests resulted in cacheable responses.)
Since this is only ever going to be used for admin views, I'm not sure how valuable this is though. I'll leave that to core committers to decide.
Comment #44
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis needed a reroll because we already introduced the
drupal-8.5.0-content_moderation_installed
fixture in #2983958: Users expect the "latest translation affected revision" not the "latest revision" in the views UI when moderating content."{$entity_type}_list"
tag.My line of thinking is: how would you ever isolate that the invalidation came from the sort plugin vs the tags that are already present from the other views subsystems (such as the display plugins) that ensure the
"{$entity_type}_list"
tag is already part of the built output of the page.In short, I don't think you could ever produce a failing test by overriding this particular plugin and returning
NULL
for all the cacheability methods.Not sure if I'm missing anything though.
Comment #45
Wim LeersComment #46
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for following up, all sounds great to me :)
Comment #48
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis just needed a reroll against #2915383: The moderation_state base field is added to all revisionable entity types even if they do not have moderation enabled.
Comment #49
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis was only rerolled and it looks like #45 is a sign-off from @Wim? :)
Comment #50
jibranRTBC +1
Comment #51
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedQueued this on a bunch of different DBs, looking solid. The sqlite fail was after it had reached the nightwatch tests:
Error retrieving a new session from the selenium server
.Comment #52
dawehner🔧 I would have actually dropped the if condition. It is potentially unlikely that the aliases is set already, but even if it is, we don't really save anything by adding this condition. It rather opens up the question, why it might or might not be set yet.
Nice extraction of logic.
I would have rather expected that the view itself has an additional sort configured, instead of altering the query, given that the sort might or might not be added at the front/back.
Adding the
hook_views_query_alter()
seems to make it much harder to understand.Comment #54
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedHey @dawehner, thanks for the review.
1. I'm fine with that change. Lets see what the bot says.
2. :)
3. I tried this in #34, but these secondary sorts are ignored when click sorting or accepting exposed input, both of which need to be tested because click sorting is integrated via the field plugin, not the sort plugin.
Comment #55
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWhoops, missed the interdiff somehow, but the only change made was addressing point 1.
Comment #56
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedPatch is looking great to me, awesome work - RTBC++
Did a minor cleanup related to CS / docblocks while I was looking at it.
Comment #57
azinck CreditAttribution: azinck at Forum One commentedHere's a backport of #56 to 8.6.x
Comment #59
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedReuploading #56 so it's clear which patch needs review.
Comment #60
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedFailing another follow-up review, RTBC for the interdiff in #56 + the scope of changes made as a result of #52 was the feedback in #52.1, so very minor.
Comment #63
oheller CreditAttribution: oheller at Electric Citizen commentedAfter applying the patch via composer after running drush updb I get the following error:
[notice] Update started: content_moderation_post_update_views_field_plugin_id
[error] Class "ConfigEntityUpdater" does not exist.
[error] Update failed: content_moderation_post_update_views_field_plugin_id
[error] Update aborted by: content_moderation_post_update_views_field_plugin_id
[error] Finished performing updates.
I suggest adding
use Drupal\Core\Config\Entity\ConfigEntityUpdater
to the top of content_moderation.post_update.php.Comment #64
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedRe #63 - that is already in the file since
8.7.x
(see https://cgit.drupalcode.org/drupal/tree/core/modules/content_moderation/...) - it's also still there on8.8.x
.Comment #65
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedI believe the tests were failing due to #3023981: Add @trigger_error() to deprecated EntityManager->EntityRepository methods, which means we can simplify
ModerationStateField
, so yay.Comment #66
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedGreat clean up, thanks for making this green again.
Comment #67
alexpottWe have a deprecation test that is failing. Keeping up with HEAD and fixing coding standards.
Comment #68
larowlanAdding review credits
Comment #69
larowlanCommitted 81d8e2a and pushed to 8.8.x. Thanks!
Not back-porting immediately because I think the update hook is disruptive at this stage of the 8.7 cycle.
Comment #71
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedYay!
So is this fixed then or is a backport a possibility?
Comment #72
xjm@larowlan, @catch, and I discussed this and agreed that it's more of a missing feature than a bug per se. It's a smidge disruptive and includes lots of additions that are only typically allowed in minor releases. So, setting fixed against 8.8.x.
Thanks everyone!
Comment #73
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedFair enough, thanks for the update @xjm!