| 7 common.inc | entity_load($entity_type, |
| 8 entity.module | entity_load($entity_type, $id, $reset = FALSE) |
Load entities from the database.
The entities are stored in a static memory cache, and will not require database access if loaded again during the same page request.
The actual loading is done through a class that has to implement the DrupalEntityControllerInterface interface. By default, DrupalDefaultEntityController is used. Entity types can specify that a different class should be used by setting the 'controller class' key in hook_entity_info(). These classes can either implement the DrupalEntityControllerInterface interface, or, most commonly, extend the DrupalDefaultEntityController class. See node_entity_info() and the NodeController in node.module as an example.
@todo Remove $conditions in Drupal 8.
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.
$conditions: (deprecated) An associative array of conditions on the base table, where the keys are the database fields and the values are the values those fields must have. Instead, it is preferable to use EntityFieldQuery to retrieve a list of entity IDs loadable by this function.
$reset: Whether to reset the internal cache for the requested entity type.
Return value
An array of entity objects indexed by their ids. When no results are found, an empty array is returned.
See also
DrupalEntityControllerInterface
7 calls to entity_load()
1 string reference to 'entity_load'
File
- includes/
common.inc, line 7620 - Common functions that many Drupal modules will need to reference.
Code
function entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {
if ($reset) {
entity_get_controller($entity_type)->resetCache();
}
return entity_get_controller($entity_type)->load($ids, $conditions);
}
Login or register to post comments
Comments
"Instead, it is preferable to
"Instead, it is preferable to use EntityFieldQuery to retrieve a list of entity IDs loadable by this function."
Example:
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'artwork', '=')
->propertyCondition('type', 'painting', '=');
$result = $query->execute();
$aids = array();
foreach($result['artwork'] as $record) {
$aids[] = $record->aid;
}
$artworks = entity_load('artwork', $aids);
for node loads eg look
for node loads eg look here:
http://stackoverflow.com/questions/6017317/entityfieldquery-multiple-alt...
Revisions without $conditions?
Without using $conditions, especially if it is to be deprecated, how would one pull an entity revision? Certainly node_load_multiple() uses $conditions to get node revisions.
Is it possible to use entity
Is it possible to use entity load with fields?? I tried but i can't make it work
Entity load with fields
Yeah, put your fields in $conditions as array like this :
$items = entity_load('node', FALSE, array('type' => 'article', 'title' => 'mytitle'));
It's possible, but depreciated
You would want to use an EntityFieldQuery instead. See http://drupal.org/node/1343708