2

I created a custom module that hides a field in a content type editing screen from the user and simultaneously auto-selects a value for that field for the user. It works great for the admin role but for some reason my other user's who are able to login and who have permission to edit the content type don't get this functionality applied. They still see the field and can still select a value for it.

Anyone know how to make the permissions for a custom module apply to ALL users?

Here's my module code:

/**
 * @file
 * Auto saving to a term reference field.
 */ 
 /** 
  * Implementation of hook_form_alter().
  */
function seven_form_resource_node_form_alter(&$form, &$form_state, $form_id) {
    hide($form['field_icon']);
}
/**
 * Implementation of hook_node_presave().
 */
function grouphideandselect_node_presave($node){
  //Condition for particular content type
  if($node->type == 'resource'){
    $icon_ary = array();
    //Array to map category with icon given as Category=>Icon
    $field_type_to_icon = array(1 => 1,2 => 1,3 => 1,4 => 2,5 => 
2,6 => 2,7 => 2,8 => 6,9 => 6,97=>6,98 => 6);
    $category = $node->field_type['und'];
    foreach($category as $k=>$c){
      $icon = $field_type_to_icon[$c['value']];
      if(!in_array($icon, $icon_ary)){
        $icon_ary[] = $icon;
        $node->field_icon['und'][$k]['tid'] = $icon;
      }
    }
  }        
}
1
  • 1
    Since you're not using the user submitted value at all, have you tried $form['field_icon']['#access'] = FALSE;? Also your hooks seem a bit off, can't figure out if your module's name is grouphideandselect or seven_form. The thing with hide() is it's more of a render thing, and can have unexpected behaviors. I'm not really sure why it's behaving like that for you (could be cache, most likely), but this has NOTHING to do with permissions
    – Beebee
    Aug 4 '15 at 16:41
1

Add the Field Permissions module, this gives you control over every field in the content type. You edit the permissions on a field by field basis in the content type editing area. This gives you control over editing, and viewing the field.

https://www.drupal.org/project/field_permissions

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.