You are here

function email_contact_mail_page_access in Email Contact 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.

@codingStandardsIgnoreStart

Parameters

string $entity_type: The entity type.

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

array $field_info: The field info for the email field.

Return value

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

1 call to email_contact_mail_page_access()
email_contact_mail_page in ./email_contact.module
The contact form page.

File

./email_contact.module, line 230
File name: email_contact.module.

Code

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

  // @codingStandardsIgnoreEnd
  // 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;
}