1

I have a submit-review process where submitters choose their reviewer. The reviewers are linked By User Reference module. Submissions are public but have an Accept/Deny review button implemented with Button Field which only should be accessible by referenced user.

Workflow fields submodule seems to accomplish that behavior but unfortunately I can't get it to work with Workflow. There is an incompatibility of versions and maintenance seems not to be very active.

So I try to build my own solution using hook_field_access() like that:

function MYMODULE_field_access($op, $field, $entity_type, $entity, $account) {
  global $user;
  if ($op == 'view' && !empty($entity) && ($field['field_name'] == 'field_accept_review' || $field['field_name'] == 'field_decline_review')) {
        // is current user == node reviewer?
        return ($entity->field_reviewer == $user->uid);
    }
}

Do I have to use user_load() before getting to the uid of the linked user?

1 Answer 1

1

I assume field_reviewer is an user reference field with only a single value allowed. If so use the following to get the referenced user's uid which is directly stored in field_reviewer array in submission:

// is current user == node reviewer?
if (!empty($entity->field_reviewer)) {
  $reviewerId = $entity->field_reviewer['uid'];
  return ($reviewerId == $user->uid);
}
return FALSE;

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.