0

Hello all and happy new year! ..

I have a question that I thought would have been answered before, but could not find anything..

I want users of a certain role to be able to edit their own content (nodes of a specific content type). This all works well. However, they can also see the 'Node Settings' option, which is a block on the right hand side with settings such as: 'CSS class(es), layout box' etc. (see picture below)

node settings

I don't want the above settings to be available to the particular role, although that role would have the right to edit the node - in other words, I want them to be able to alter content, but not be able to mess around with css classes, layout boxes and anything like that ...

Ideally, I would like that whole 'Node Settings' block to be available only to administrators, and not to users of any role - even if they do have permissions to edit the content of that particular node.

I looked carefully into permissions and searched the web, but could not find anything ... My feeling is that this should be done as it must be quite a frequent case ..

Any help would be greatly appreciated.

1

I think that this is quite easy using hook_form_FORM_ID_alter like this,

function MY_MODULE_form_node_form_alter(&$form, &$form_state, $form_id) {
  $current_user = \Drupal::currentUser();
  $roles = $current_user->getRoles();
  if (in_array('YOUR_ROLE', $roles)) {
    unset($form['...']);
  }
}

if you don't know what the name of the element is called, try to find it using kint($node) if you have devel installed.

Hope it works for you.

  • Thanks for your input. I guess this must be the best way. However, I don't know yet how to play with those functions - I guess I really need to learn the Drupal API and study how to create custom modules (this is what you do with the above code, if I am not mistaken). I have found some info on the web, but if you know a good tutorial please let me know. Documentation pages are quite bewildering for a newbie like myself. Anyway, I think I might just disable the settings for the CT config page for the time being. Thanks again for your help.. – thomas Jan 9 at 17:03
  • This guide is really good drupal.org/docs/8/creating-custom-modules – Jdrupal Jan 9 at 21:42
  • The code I wrote you need to add in your custom module in a MODULENAME.module file, that will be a PHP file – Jdrupal Jan 9 at 21:43

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.