is there a simple way to control the node's publish state under a content type? eg: a content type "test", when the content is created by the admin, the article will be published. when the user iseditor, the article will be approved by admin that can publish. when i unchecked the box(published) which in the content type test workflow settings. both the admin and editor creating articles are can't be published

2 Answers 2


As Berdir stated you could use the rules module to un/publish specific content depending to the role of the creator. You could also implement hook_nodeapi() in a module to get this done. The operation would be 'presave' and the code something like that:

YOURMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    if($op == 'presave' && $node->type == 'YOURTYPE') {
        global $user;
        if (in_array('YOURROLE', array_values($user->roles))) {
            $node->status = 0;

Here I checked the contenttype and user role to upublish content. You can do all sort of things.

  • i am sorry, i have tested the above code, but it can't work. when i publish a story as role administrator. then i logout to see the page, it shows i have no perssion to access the page, the articles status is unpublished.
    – enjoylife
    May 9, 2011 at 12:18
  • The code requires the nodes to be published by default. It unpublishes them if the constraints (contentype + role) hit. You could do it the other way around (status = 1) if that fits your problem better (e.g. there are 10 roles which can't publish and only one is allowed to).
    – nonsenz
    May 9, 2011 at 12:29
  • i changed the $node->status = 1; it still can't work. i want to the administrator role publish. the rest role unpublish.
    – enjoylife
    May 9, 2011 at 12:39
  • Could you post your code? Can you debug (dsm() or print_r()) and check if the code inside the inner if is ever reached? Is the module not activated or are there any typos?
    – nonsenz
    May 9, 2011 at 13:05
  • function alterform_nodeapi(&$node,$op,$a3=NULL,$a4=NULL){ if($op== 'presave' && $node->type == 'story'){ global $user; if(in_array('administrator',array_values($user->roles))){ $node->status =1;}}}
    – enjoylife
    May 9, 2011 at 13:16

If you change the default to don't publish, only users with the appropriate permission can change it, for all others, it will use the default.

You could then for example build a view with unpublished content, that you can go through and publish want you want. The default content list has a filter to show only unpublished content too, so that might work too.

  • i am sorry,the description of my question maybe unclearly. i want to when the admin creates the article that published. the editor can't.
    – enjoylife
    May 9, 2011 at 9:28
  • 2
    Have a look at drupal.org/project/rules then, that might help you.
    – Berdir
    May 9, 2011 at 9:30

Your Answer

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

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