You are here

function _juicebox_check_entity_view_access in Juicebox HTML5 Responsive Image Galleries 7

Check view access for an arbitrary entity that contains a Juicebox gallery.

Parameters

string $entity_type: The type of entity being checked (e.g. "node").

object $entity: The full entity object that the Juicebox gallery field is attached to.

Return value

boolean Returns TRUE if view access is allowed for the current user or FALSE if not. If access cannot be confirmed, returns NULL.

1 call to _juicebox_check_entity_view_access()
juicebox_page_xml in ./juicebox.module
Menu callback: generate Juicebox XML.

File

./juicebox.module, line 499
Provides Drupal integration with the Juicebox library.

Code

function _juicebox_check_entity_view_access($entity_type, $entity) {

  // If the Entity API module is installed we can use entity_access() to check
  // access for numerous entity types via their access callbacks. All core
  // entities, and many custom ones, can be handled here.
  if (module_exists('entity')) {
    return entity_access('view', $entity_type, $entity);
  }

  // If we can't do a check with entity_access() we only maintain checks for a
  // couple popular core entity types that provide thier own explicit access
  // functions.
  switch ($entity_type) {
    case 'node':
      return node_access('view', $entity);
    case 'user':
      return user_view_access($entity);
  }

  // Log a warning and return NULL if we can't do a conclusive check.
  watchdog('juicebox', 'Could not verify view access for entity type %type while building Juicebox XML. This may have resulted in a broken gallery display. You may be able to remove this error by installing the Entity API module and ensuring that an access callback exists for entities of type %type.', array(
    '%type' => $entity_type,
  ), WATCHDOG_ERROR);
}