Dispatch events for changing content moderation states

Created on 27 April 2017, over 7 years ago
Updated 8 February 2024, 10 months ago

Problem/Motivation

The ContentModerationState entity type is @internal so any time users interact with it directly, they are risking API breaks. One of the convenient touch points with the entity is implementing hook_entity_(insert|update) as seen in the content_moderation_notifications. Implementing these hooks gives you a single place to react to content states changes.

Proposed resolution

Provide an alternative to these hooks so users have a consistent and @api way to react to any item of content having its state changed. An event suits this purpose nicely.

Remaining tasks

#39 = https://www.drupal.org/project/drupal/issues/2873287#comment-12304979 πŸ“Œ Dispatch events for changing content moderation states Needs work
Change record.

Review and commit.

User interface changes

None.

API changes

An additional event.

Data model changes

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Content moderationΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡¦πŸ‡ΊAustralia Sam152

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • last update over 1 year ago
    Patch Failed to Apply
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    That also needed to happen in tests.
    Fixed that, and the method signature forces us to return something (usually the event itself). This should be green.

    Next step should be fixing the php10 deprecation warnings.

  • last update over 1 year ago
    29,343 pass, 1 fail
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    That was the interdiff only... not even properly named.

  • last update over 1 year ago
    Custom Commands Failed
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Rewritten the test based on πŸ“Œ InvocationMocker::withConsecutive() is deprecated in PHPUnit 9.6 and removed from PHPUnit 10 RTBC . Added a todo if this lands before that one. No deprecations anymore.
    I feel like writing tests will be even harder now :-(

  • last update over 1 year ago
    29,360 pass
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Mostly code standards, but I changed an exactly(5) to any() in previous patch and I reverted that back.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Per #39 still NW.

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    Custom Commands Failed
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Just another rebase, conflict on the save method changes.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Updated remaining tasks to include #39 + change record.

  • πŸ‡¬πŸ‡·Greece gbotis

    patch from #76 does not apply to 10.2.2

  • for 10.2.x use patch from #79

  • πŸ‡ͺπŸ‡ΈSpain willeaton

    Hi, I was looking for this functionality, its great for being informed of a transition event, but what about being able to veto the transition?

    Use case: Product publication.

    A user wants to validate a product ready for publication. The system needs to check that the product is really ready. Maybe they haven't filled in all the required fields for publication (fields which cannot be required to create the initial entity/node). Maybe they haven't prepared related content which is required for publication.

    The system should be able to validate certain data before allowing the product to pass to a validated state.

    Previously we used the "Workflow" module but we decided against it because the module doesn't seem to be maintained and the code base is still in a state of temporary migration from Drupal 7 style code. Content Moderation seemed to be the more accepted option however it is limited in this respect.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    @willeaton: You might find State Machine β†’ suitable for your needs. It provides / supports "Guards" which are plugins you can define to prevent specific state transitions if certain conditions are not met. But we're getting a bit off topic from this issue.

    I also needed something like this for a project, but this issue seems a potentially doomed in deadlock between release manager and subsystem maintainer. I'm not sure I can be more persuasive than what @Sam152 already said in #40 and #45. Yes, a mix of hooks and events is somewhat crappy DX, but so is the current situation. I'm not sure how we provide 100% BC without a mix of both unless we want to make ContentModerationState public API. Drupal seems to love to provide a lot of different ways to alter the same thing πŸ˜… so I'm not totally convinced that having both Events and hooks is really all that terrible. πŸ˜‚

    +1 to doing this. If I can find more time for a direct (and hopefully persuasive) response to every point in #39, I'll try.

Production build 0.71.5 2024