1

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 ?

2
  • Both are possible, but the second option probably makes more sense. For how to load the node, see drupal.stackexchange.com/questions/303872/…, only that you set a different moderation state.
    – 4uk4
    Apr 4, 2023 at 13:42
  • thanks @4uk4 yes loading the last revision makes more sense
    – arirams
    Apr 5, 2023 at 6:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.