0

For every user with role company manager i have made tab My company(in user profile) where user can see node_edit of their company(node). And i need to set default format to plain-text and hide text-format drop down list only for this role. Ofc. i can do this for every user, i can change settings in my content type field settings, but this way the other users will not see it too.

Any suggestions? how can i achieve this?

1
  • What do you mean when you say, "where user can see node_edit of their company(node)"?
    – avpaderno
    Commented Jan 5, 2013 at 19:30

4 Answers 4

0

This can be achieved by some coding. If it is okay to make a custom module then it can be done via hook_form_alter(&$form, &$form_state, $form_id)

In this hook get a debug statement to get the form id for your node edit page. Now in that page you need to get the type of node being edited. So there are 3 things to look for.

  1. Get the form_id for the node edit page. Then use this in a switch-case statement to perform your logic.
  2. Then get the Node type that is being edited, from the URL. So if you are in a edit page then the URL will be like, http://example.com/node/14/edit. For arg(2) you will get the node id. Perform a node_load and call node_type_get_name($node) or just a simple database query to node table by node id will do it for you.
  3. Check for the User role and decide to show/hide the select box.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
    global $user;
    switch($form_id) {
       case "node-edit_form" : //may differ as I am only giving a demo
         //Add your logic
         $nid = arg(2); //Add some isset check will be good and filter_xss() for security purpose. 
         $node_type = db_select('node', 'n')->fields('n', array('type'))->condition('nid', $nid, '=')->execute()->fetchObject();
         if($node_type->type == 'your_needed_type') {
              if(array_key_exists('company manager', $user->roles)) {
                  $form['#after_build'][] = 'mymodule_your_needed_type_node_form_after_build';
              }
         }
       break;
    }
}

function mymodule_your_needed_type_node_form_after_build($form) {
    // We want this on a specific field
    $form[LANGUAGE_NONE]['0']['format']['#access'] = FALSE;
    return $form;
}

I think this will solve the issue for you. You can do some R&D and make it more efficient like to add more checks.

0
1

Alternatively, you can use the Better Formats module, it gives a lot of possibilities to you to control text format selection.

1

Instead of coding, this can be achieved from admin configuration in drupal 7.

Go to

Configurations > Content Authoring > Text formats

at this page, you can set restriction against your roles.

0

A simple but relevant sledgehammer approach would be to revoke permission to use anything but the plain-text format, using user_role_revoke_permissions. (Similarly, if you want to add permissions to use a given text format for a given role, use user_role_grant_permissions.)

user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID,
   array(... 'use text format filtered_html', ...));

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.