You are here

function _sheetnode_load_entity in Sheetnode 6

Helper function to load a Drupal entity.

2 calls to _sheetnode_load_entity()
_sheetnode_ajax_field in ./sheetnode.module
AJAX function to return a field value.
_sheetnode_ajax_token in ./sheetnode.module
AJAX function to return a token value.

File

./sheetnode.module, line 1102

Code

function _sheetnode_load_entity($entity_type, $oid, $op = 'view', $account = NULL) {

  // First try VBO and its hook_views_bulk_operations_object_info()
  // that approximates D7 entities.
  if (module_exists('views_bulk_operations')) {
    $object_info = _views_bulk_operations_get_object_info();
    if (isset($object_info[$entity_type])) {
      if (function_exists($object_info[$entity_type]['load'])) {
        $entity = call_user_func($object_info[$entity_type]['load'], $oid);
        if (function_exists($object_info[$entity_type]['access'])) {
          if (!call_user_func($object_info[$entity_type]['access'], $op, $entity, $account)) {
            return NULL;
          }
        }
        return $entity;
      }
    }
  }

  // Otherwise, call a load function on the passed entity type.
  if (function_exists($entity_type . '_load')) {
    $entity = call_user_func($entity_type . '_load', $oid);
    if ($entity_type === 'node') {
      if (!node_access($op, $entity, $account)) {
        return NULL;
      }
    }
    return $entity;
  }

  // Otherwise, fail.
  watchdog('sheetnode', 'Could not load entity type %entity_type: No load function found.', array(
    '%entity_type' => $entity_type,
  ), WATCHDOG_WARNING);
  return NULL;
}