Score:1

Content moderation and changing node state on default or latest revision

gh flag

I am using content moderation and sometimes I update the moderation state of my entity programmatically in a hook node presave for example. I usually have the entity and I can do $node->set('moderation_state', "needs review"); , however my question is, if for some reason in a controller, I want to do the same thing in a function that doesn't have the node entity as parameter, I wanna load the node by ID then change its state. should I use Node::Load($nid); which gives me the node default/current version before doing $node->set('moderation_state', "needs review"); or should I have to load the latest revision then set the moderation state on the latest revision instead of setting it on the current/default revision ?

4uk4 avatar
cn flag
Both are possible, but the second option probably makes more sense. For how to load the node, see https://drupal.stackexchange.com/questions/303872/how-do-i-programmatically-publish-the-latest-revision, only that you set a different moderation state.
arirams avatar
gh flag
thanks @4uk4 yes loading the last revision makes more sense
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.