You are here

function email_mail_page_access in Email Field 7

Access callback for the email contact page.

Checks whether the current user has view access to the entity. Access checks are performed for the fieldable core entity types, including nodes, users, comments and taxonomy terms. Furthermore entity types using Entity API's access system are supported. For custom entity types that are not using the Entity API, at least the access content permission is checked in the menu access callback.

This function is called within the email page callback, as it takes care of loading the entity itself. If the entity is found, access checks are performed with this function.

Parameters

$entity_type: The entity type

$entity: The entity for which the access should be checked

$field_info: The field info for the email field.

Return value

TRUE if the current user has view access, otherwise FALSE.

1 call to email_mail_page_access()
email_mail_page in ./email.module
The contact form page.

File

./email.module, line 236
Module file for the email module, which creates a email address field.

Code

function email_mail_page_access($entity_type, $entity, $field_info) {

  // Check for field access.
  if (!field_access('view', $field_info, $entity_type, $entity)) {
    return FALSE;
  }

  // Check the access for fieldable core entities, including nodes, users,
  // comments and taxonomy terms.
  if ($entity_type == 'node') {
    return node_access('view', $entity);
  }
  elseif ($entity_type == 'user') {
    global $user;
    if ($entity->uid == $user->uid && $entity->uid) {
      return TRUE;
    }
    if (user_access('administer users') || user_access('access user profiles') && $entity->status) {
      return TRUE;
    }
    return FALSE;
  }
  elseif ($entity_type == 'comment') {
    return comment_access('view', $entity);
  }
  elseif ($entity_type == 'taxonomy_term') {
    if (user_access('administer taxonomy') || user_access('access content')) {
      return TRUE;
    }
    return FALSE;
  }

  // Use Entity API for checking the view access for non-core entity types, if
  // the module is installed.
  if (module_exists('entity')) {
    return entity_access('view', $entity_type, $entity);
  }
  return TRUE;
}