Problem/Motivation

The ContentModerationState implements the ContentModerationStateInterface, but that interface is empty.

The public custom methods should be part of that interface. It would also be nice to have a method to retrieve the moderated entity, since that must be done now by directly accessing the content_entity_id value.

Proposed resolution

Add a new method getModeratedEntity(), and add the public methods to the interface.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new2.79 KB

I left the getCurrentUserId() method off of the interface since that is a default value callback specific to the implementation. This probably needs some tests, but its a start.

jhedstrom’s picture

StatusFileSize
new1.98 KB
new2.71 KB

That last patch had an error where the interface referenced the implementation. As I fixed this though, I noticed that this method presumably is not used anywhere:

  public static function updateOrCreateFromEntity(ContentModerationStateInterface $content_moderation_state) {
    $content_moderation_state->realSave();
  }

since it's calling a protected method there...

sam152’s picture

This is an interesting one. I don't really feel like the ContentModerationState should be the go-to way of interacting with the moderation states, all of that should be done through the computed field if possible. Adding methods to the interface would encourage it as a part of the public API. It raises the question if that whole entity type should be @internal. Or at least there should be a review of the methods to see what should be internal or not, getCurrentUserId seems like a candidate.

Is this use case based on the result of an entity query, or something similar? Maybe we can provide some wrapper around these kind of queries to abstract the details of the underlying entity away. I wonder how hard it would be to make entity query work to join against content_moderation_state so you could simply go ->condition('moderation_state', 'draft'); on a node entity query for example.

Also, you can call protected methods on objects if the method doing the calling is on the same class the protected method is on, even if the entity !== $this.

timmillwood’s picture

I mostly agree with #4, content_moderation_state entity shouldn't be where you go to interact with moderation states, and maybe we should mark it as @internal.

The content_moderation_state entity is sometimes useful when wanting a list of all "archived" entities across different entity types, which I hope we'll be able to do in Views, but other than that you should come via the computed moderation_state field.

Maybe we should remove the ContentModerationStateInterface?

jhedstrom’s picture

Is this use case based on the result of an entity query, or something similar?

It's utilized in hook_ENTITY_TYPE_update to generate notifications of state change for content--is there a better way to hook into that process?

timmillwood’s picture

@jhedstrom - That is the best way, Workbench Moderation used to fire an event, but when we switched to use a content entity for storage there was no need for the event as we have a hook. So I guess for this use case it kinda makes sense.

sam152’s picture

@jhedstrom, how would you feel about doing something like #2873287: Dispatch events for changing content moderation states instead? It would be part of the effort to ensure people don't have to understand and interact with the ContentModerationState entity directly. I think it'll be marked @internal at some point and we're already doing things like #2779931, which deny all access to it for CRUD purposes.

jhedstrom’s picture

@Sam152 I think that would be ok. However, as long as this is an entity, folks will find a way to do something crazy with it directly ;)

jhedstrom’s picture

Status: Needs review » Closed (works as designed)