I have a view page which display node titles?

I'm also using workbench moderation module. During views rendering I check nodes and on certain condition I'm publishing the node from draft state using workbench_moderation_moderate($node, 'published');.

So is there any views hook Where i can use to set a revision of a node to publish and then views fetch the node's updated data?

I have tried hook_preprocess_views_view(&$vars) but it moderate the node to publish but then display the updated data on 2nd page referesh.


Assuming this is Drupal 7.

hook_preprocess_views_view() runs after the query is performed. You could try using hook_views_pre_view() or hook_views_query_alter(), both of which happen before the query runs, and save the nodes at that time. Of course the results of the view will not be available to you then, so you would have to select the nodes in some other way.

Also neither of these hooks work in themes, you would have to use a custom module.


  • it will not create overhead for large views? – Ahmad Aug 1 '16 at 17:26
  • Well, most of the overhead is probably the fact that this strategy makes caching the view impossible. Depending on how important it is to have those nodes be updated at the specific moment that someone visits the view, I would definitely advise a different strategy if possible. You could set up a cron job to check the nodes, or use rules to do the same, and then use something like drupal.org/project/views_content_cache (or a custom implementation) that would expire the cache for that view whenever a node became published. – David Hunt Aug 1 '16 at 18:05
  • in my case the views cache is not enabled. – Ahmad Aug 1 '16 at 18:18
  • is there no any other method where I can get the results from views and perform moderation and then views render that moderated content? – Ahmad Aug 2 '16 at 7:09
  • Sorry, maybe my previous comment was unclear: if you don't have a views cache enabled, and you don't plan on enabling any views cache, then the overhead added by the approach above should be very small, though of course it depends on what you are doing to determine which nodes need to be updated. If that is simple, then small overhead; if you're loading every single node and performing complex checks on them, then large overhead. Anyway, those two hooks are the way I would use if I wanted to affect anything before a view got its results. – David Hunt Aug 5 '16 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.