I have several types of content that are moderated(content_moderation and workflows), in a custom validation process I need to know if a particular node has at least one published revision. Is there a way to obey only the revisions of a node that are only published?

I found this example on a node core module controller:

protected function getRevisionIds(NodeInterface $node, NodeStorageInterface $node_storage) {
    $result = $node_storage->getQuery()
      ->condition($node->getEntityType()->getKey('id'), $node->id())
      ->sort($node->getEntityType()->getKey('revision'), 'DESC')
    return array_keys($result);

But this returns all the revisions and I am trying to avoid loading each of the revisions to search for the published ones and if I can bring the id of only the published ones it would be the best in my case.

  • Isn't this simply going to amount to the set of all published nodes (and their current revision)? You can't have two revisions of a node published at the same time. Oct 16, 2019 at 16:20
  • @AlfredArmstrong The reviews are historical and if there can be more than one published review, but only the last one published is the one shown on the site, once each content ends the flow if a published version already existed it is replaced by the last one.
    – chalo
    Oct 16, 2019 at 17:09


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.