1

I have two roles Editor and Manager. Editor can add nodes as unpublished and manager can review the nodes and approve/publish them in website.

For administration I am using default SEVEN theme for adding/editing nodes. How can i hide "Save and Publish" button to editor role only?

Can it possible by calling a template hook node_presave? I tried below code but not worked.

 function seven_node_presave($node) {
    global $user;

    if (in_array('editor',$user->roles)){
        $node->status = FALSE;
    }

}

if any body can suggest solution for this?

1

How can i hide "Save and Publish" button to editor role only?

You can use two ways.

  1. Simple ways. Enable module Content Moderation in core and set permission by roles.

  2. Use function hook_form_node_form_alter()

global $user;

if (in_array('editor',$user->roles)){
   $node->status = FALSE;
}

Drupal 8 have some different. Global user replace by
\Drupal::currentUser()

and $user->roles replace by

\Drupal::currentUser()->getRoles()

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.