I'd think you could just add
!$cuid
so it looks like
if (!$cuid || $user->uid == $cuid || $user->uid == $nuid)
since $cuid should be undefined when the comment is new.
문제
I have a Drupal site and would like to make some comment fields (for the content type "event") only seen by the comment author and the comment node author. These fields are, "field_how_to_redeem_this_offer", "field_date" and "comment_body". I tried using the module, Private Comments but that only gives you the option to make the whole comment private, not just some of the fields. So, I had a developer create a custom module and it works except, when creating a new comment the fields I specified above are not shown and they should be. I'm guessing that's because when creating a new comment the comment author has not been assigned yet so I need to change the code so that when a new comment is being created (or comment form is viewed), all fields should be available to the user. Is there a way to do this? Please see the code bellow:
`function bidonmybash_field_access($op, $field, $entity_type, $entity, $account) {
global $user;
$fields = array('field_how_to_reedem_this_offer','field_date','comment_body');
if (in_array($field['field_name'],$fields)) {
if ($entity) {
if (isset($entity->node_type)) {
if ($entity->node_type == 'comment_node_event') {
$cuid = $entity->uid;
$node = node_load($entity->nid);
$nuid = $node->uid;
if ($user->uid == $cuid || $user->uid == $nuid) {
return TRUE;
}
else {
return FALSE;
}
}
}
}
}
}`
Thanks in advance for your help!
해결책
I'd think you could just add
!$cuid
so it looks like
if (!$cuid || $user->uid == $cuid || $user->uid == $nuid)
since $cuid should be undefined when the comment is new.