function tripal_load_entity

3.x tripal.entities.api.inc tripal_load_entity($entity_type, $ids = FALSE, $reset = FALSE, $field_ids = array(), $cache = TRUE)

A replacement for the entity_load function of Drupal.

This function should be used for loading of Tripal Entities. It provides greater control to limit which fields are loaded with the entity. The entity_load() function of Drupal will automatically attach all fields at once but this may not be desired as some fields can be complex and large, and the site developer may desire loading of fields via AJAX or the user of web services may wish to specify the fields they want to include.

Parameters

$entity_type:: The entity type to load, e.g. node or user.

$ids: An array of entity IDs, or FALSE to load all entities.

$reset: Whether to reset the internal cache for the requested entity: type. Defaults to FALSE.

$field_ids: A list of numeric field IDs that should be loaded. The TripalField named 'content_type' is always automatically added.

$cache: When loading of entities they can be cached with Drupal for later faster loading. However, this can cause memory issues when running Tripal jobs that load lots of entities. Caching of entities can be disabled to improve memory performance by setting this to FALSE.

Return value

An array of entity objects indexed by their ids. When no results are found, an empty array is returned.

Related topics

10 calls to tripal_load_entity()
TripalContentService_v0_1::doEntity in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Creates a resource for a single entity.
TripalContentService_v0_1::doEntityList in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Creates a collection of resources for a given type.
TripalContentService_v0_1::doExpandedField in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Creates a resource for an expanded field of an entity.
TripalContentService_v0_1::sanitizeFieldEntity in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Rewrites any TripalEntity elements in the values array for use with WS.
TripalEntityCollection::write in tripal/includes/TripalEntityCollection.inc
Writes the collection to a file using a given formatter.

... See full list

File

tripal/api/tripal.entities.api.inc, line 212
Provides an application programming interface (API) for working with TripalEntity content types (bundles) and their entities.

Code

function tripal_load_entity($entity_type, $ids = FALSE, $reset = FALSE, 
$field_ids = array(), $cache = TRUE) {

  // The $conditions is deprecated in the funtion arguments of entity_load
  // so it was removed from the parameters of this function as well. But
  // the load() function of the entity controller still expects it so set it
  // to an empty array.
  $conditions = array();

  // If this isn't a TripalEntity then just load it the old fashioned way
  // although caching will not be used if it not specifically set to FALSE.
  if ($entity_type != 'TripalEntity') {
    return entity_load($entity_type, $ids, $conditions, $reset);
  }

  // Get the entity controller and clear the cache if requested (default).
  $ec = entity_get_controller($entity_type);
  if ($reset) {
    $ec->resetCache();
  }

  return $ec->load($ids, $conditions, $field_ids, $cache);
}