Currently, access to the field is done in the widget itself, which is not such a good idea imo.

A problem I experienced, I had the field in a vertical tab (fieldgroup), and for users without access to the field, the fieldgroup would appear empty (while it should be hidden.
Checking the html, I saw an empty html container for the radioactivity field.

This can be fixed by adding the following implementation of hook_field_access:

/**
 * Implements hook_field_access().
 */
function radioactivity_field_access($op, $field, $entity_type, $entity, $account) {
  if ($field['type'] == 'radioactivity' && $op == 'edit') {
    return user_access("edit radioactivity");
  }
  return TRUE;
}
CommentFileSizeAuthor
#1 radioactivity_field_access-1941734-1.patch1.52 KBrv0
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rv0’s picture

Issue summary: View changes

typo

rv0’s picture

Got burned by this again. Adding a patch.
This also corrects the documentation of the widget function and removes the redundant access check there.

rv0’s picture

bump

rv0’s picture

bump^2

  • Sutharsan committed ac0b27b on 7.x-2.x authored by rv0
    Issue #1941734 by rv0: Implement hook_field_access
    
Sutharsan’s picture

Status: Needs review » Fixed

Better late then never ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.