Commit 4daf1c63 authored by catch's avatar catch

Issue #1160566 by Dave Reid, bdlangton, aspilicious, fago, cosmicdreams,...

Issue #1160566 by Dave Reid, bdlangton, aspilicious, fago, cosmicdreams, tstoeckler, tim.plunkett, Berdir, sun: Entity_load() is actually entity_load_multiple().
parent 52d7970b
......@@ -576,16 +576,16 @@ function file_save_htaccess($directory, $private = TRUE) {
/**
* Loads file objects from the database.
*
* @param $fids
* An array of file IDs.
* @param $conditions
* @param array|bool $fids
* An array of file IDs, or FALSE to load all files.
* @param array $conditions
* (deprecated) An associative array of conditions on the {file_managed}
* 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.
*
* @return
* @return array
* An array of file objects, indexed by fid.
*
* @todo Remove $conditions in Drupal 8.
......@@ -595,8 +595,8 @@ function file_save_htaccess($directory, $private = TRUE) {
* @see entity_load()
* @see EntityFieldQuery
*/
function file_load_multiple($fids = array(), $conditions = array()) {
return entity_load('file', $fids, $conditions);
function file_load_multiple($fids = array(), array $conditions = array()) {
return entity_load_multiple('file', $fids, $conditions);
}
/**
......
......@@ -1500,19 +1500,19 @@ function comment_delete_multiple($cids) {
/**
* Loads comments from the database.
*
* @param $cids
* An array of comment IDs.
* @param $conditions
* @param array|bool $cids
* An array of comment IDs, or FALSE to load all comments.
* @param array $conditions
* (deprecated) An associative array of conditions on the {comments}
* 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.
* @param $reset
* @param bool $reset
* Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default.
*
* @return
* @return array
* An array of comment objects, indexed by comment ID.
*
* @todo Remove $conditions in Drupal 8.
......@@ -1520,16 +1520,16 @@ function comment_delete_multiple($cids) {
* @see entity_load()
* @see EntityFieldQuery
*/
function comment_load_multiple($cids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('comment', $cids, $conditions, $reset);
function comment_load_multiple($cids = array(), array $conditions = array(), $reset = FALSE) {
return entity_load_multiple('comment', $cids, $conditions, $reset);
}
/**
* Loads the entire comment by comment ID.
*
* @param $cid
* @param int $cid
* The ID of the comment to be loaded.
* @param $reset
* @param bool $reset
* Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default.
*
......@@ -1537,8 +1537,7 @@ function comment_load_multiple($cids = array(), $conditions = array(), $reset =
* The comment object.
*/
function comment_load($cid, $reset = FALSE) {
$comment = comment_load_multiple(array($cid), array(), $reset);
return $comment ? $comment[$cid] : FALSE;
return entity_load('comment', $cid);
}
/**
......
......@@ -123,6 +123,7 @@
* display settings specific to the view mode.
*
* @see entity_load()
* @see entity_load_multiple()
* @see hook_entity_info_alter()
*/
function hook_entity_info() {
......@@ -427,7 +428,7 @@ function hook_entity_view_alter(&$build, $type) {
* Act on entities as they are being prepared for view.
*
* Allows you to operate on multiple entities as they are being prepared for
* view. Only use this if attaching the data during the entity_load() phase
* view. Only use this if attaching the data during the entity loading phase
* is not appropriate, for example when attaching other 'entity' style objects.
*
* @param $entities
......
......@@ -191,7 +191,31 @@ function entity_create_stub_entity($entity_type, $ids) {
}
/**
* Loads entities from the database.
* Loads an entity from the database.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param int $id
* The id of the entity to load.
* @param bool $reset
* Whether to reset the internal cache for the requested entity type.
*
* @return object
* The entity object, or FALSE if there is no entity with the given id.
*
* @see hook_entity_info()
* @see entity_load_multiple()
* @see DrupalEntityControllerInterface
* @see DrupalDefaultEntityController
* @see EntityFieldQuery
*/
function entity_load($entity_type, $id, $reset = FALSE) {
$entities = entity_load_multiple($entity_type, array($id), array(), $reset);
return isset($entities[$id]) ? $entities[$id] : FALSE;
}
/**
* Loads multiple entities from the database.
*
* This function should be used whenever you need to load more than one entity
* from the database. The entities are loaded into memory and will not require
......@@ -206,19 +230,19 @@ function entity_create_stub_entity($entity_type, $ids) {
* DrupalDefaultEntityController class. See node_entity_info() and the
* NodeController in node.module as an example.
*
* @param $entity_type
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param $ids
* @param array|bool $ids
* An array of entity IDs, or FALSE to load all entities.
* @param $conditions
* @param array $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.
* @param $reset
* @param bool $reset
* Whether to reset the internal cache for the requested entity type.
*
* @return
* @return array
* An array of entity objects indexed by their ids.
*
* @todo Remove $conditions in Drupal 8.
......@@ -228,7 +252,7 @@ function entity_create_stub_entity($entity_type, $ids) {
* @see DrupalDefaultEntityController
* @see EntityFieldQuery
*/
function entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {
function entity_load_multiple($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {
if ($reset) {
entity_get_controller($entity_type)->resetCache();
}
......
......@@ -733,7 +733,7 @@ public function addMetaData($key, $object) {
* @code
* $result = $query->execute();
* if (!empty($result[$my_type])) {
* $entities = entity_load($my_type, array_keys($result[$my_type]));
* $entities = entity_load_multiple($my_type, array_keys($result[$my_type]));
* }
* @endcode
*/
......
......@@ -29,34 +29,33 @@ function entity_test_entity_info() {
/**
* Loads a test entity.
*
* @param $id
* @param int $id
* A test entity ID.
* @param $reset
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @return Entity
* The loaded entity object, or FALSE if the entity cannot be loaded.
*/
function entity_test_load($id, $reset = FALSE) {
$result = entity_load('entity_test', array($id), array(), $reset);
return reset($result);
return entity_load('entity_test', $id, $reset);
}
/**
* Loads multiple test entities based on certain conditions.
*
* @param $ids
* An array of entity IDs.
* @param $conditions
* @param array|bool $ids
* An array of entity IDs, or FALSE to load all entities.
* @param array $conditions
* An array of conditions to match against the {entity} table.
* @param $reset
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @return
* @return array
* An array of test entity objects, indexed by ID.
*/
function entity_test_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('entity_test', $ids, $conditions, $reset);
return entity_load_multiple('entity_test', $ids, $conditions, $reset);
}
/**
......
......@@ -163,8 +163,7 @@ function file_file_download($uri, $field_type = 'file') {
foreach ($field_references as $entity_type => $type_references) {
foreach ($type_references as $id => $reference) {
// Try to load $entity and $field.
$entity = entity_load($entity_type, array($id));
$entity = reset($entity);
$entity = entity_load($entity_type, $id);
$field = NULL;
if ($entity) {
// Load all fields for that entity.
......
......@@ -56,8 +56,8 @@
* - hook_entity_update() (all)
* - hook_node_access_records() (all)
* - hook_node_access_records_alter() (all)
* - Loading a node (calling node_load(), node_load_multiple(), or
* entity_load() with $entity_type of 'node'):
* - Loading a node (calling node_load(), node_load_multiple(), entity_load()
* or entity_load_multiple() with $entity_type of 'node'):
* - Node and revision information is read from database.
* - hook_load() (node-type-specific)
* - field_attach_load_revision() and field_attach_load()
......
......@@ -913,40 +913,40 @@ function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
* from the database. Nodes are loaded into memory and will not require
* database access if loaded again during the same page request.
*
* @param $nids
* (optional) An array of node IDs.
* @param $conditions
* @param array|bool $nids
* (optional) An array of node IDs, or FALSE to load all nodes.
* @param array $conditions
* (deprecated) An associative array of conditions on the {node}
* 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.
* @param $reset
* @param bool $reset
* (optional) Whether to reset the internal node_load() cache.
*
* @return
* @return array
* An array of node objects indexed by nid.
*
* @todo Remove $conditions in Drupal 8.
*
* @see entity_load()
* @see entity_load_multiple()
* @see EntityFieldQuery
*/
function node_load_multiple($nids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('node', $nids, $conditions, $reset);
function node_load_multiple($nids = array(), array $conditions = array(), $reset = FALSE) {
return entity_load_multiple('node', $nids, $conditions, $reset);
}
/**
* Loads a node object from the database.
*
* @param $nid
* @param int $nid
* (optional) The node ID.
* @param $vid
* @param int $vid
* (optional) The revision ID.
* @param $reset
* @param bool $reset
* (optional) Whether to reset the node_load_multiple() cache.
*
* @return
* @return object
* A fully-populated node object, or FALSE if the node is not found.
*/
function node_load($nid = NULL, $vid = NULL, $reset = FALSE) {
......
......@@ -60,7 +60,7 @@ class NodeLoadMultipleUnitTest extends NodeWebTestCase {
$this->assertNoText($node4->title, t('Node title does not appear in the default listing.'));
// Load nodes with only a condition. Nodes 3 and 4 will be loaded.
$nodes = node_load_multiple(NULL, array('promote' => 0));
$nodes = node_load_multiple(FALSE, array('promote' => 0));
$this->assertEqual($node3->title, $nodes[$node3->nid]->title, t('Node was loaded.'));
$this->assertEqual($node4->title, $nodes[$node4->nid]->title, t('Node was loaded.'));
$count = count($nodes);
......
......@@ -1321,7 +1321,7 @@ class MenuBreadcrumbTestCase extends MenuWebTestCase {
// the breadcrumb based on taxonomy term hierarchy.
$parent_tid = 0;
foreach ($tags as $name => $null) {
$terms = taxonomy_term_load_multiple(NULL, array('name' => $name));
$terms = taxonomy_term_load_multiple(FALSE, array('name' => $name));
$term = reset($terms);
$tags[$name]['term'] = $term;
if ($parent_tid) {
......
......@@ -938,53 +938,53 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
* from the database. Terms are loaded into memory and will not require
* database access if loaded again during the same page request.
*
* @see entity_load()
* @see entity_load_multiple()
* @see EntityFieldQuery
*
* @param $tids
* An array of taxonomy term IDs.
* @param $conditions
* @param array|bool $tids
* An array of taxonomy term IDs, or FALSE to load all terms.
* @param array $conditions
* (deprecated) An associative array of conditions on the {taxonomy_term}
* 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.
*
* @return
* @return array
* An array of taxonomy term entities, indexed by tid. When no results are
* found, an empty array is returned.
*
* @todo Remove $conditions in Drupal 8.
*/
function taxonomy_term_load_multiple($tids = array(), $conditions = array()) {
return entity_load('taxonomy_term', $tids, $conditions);
function taxonomy_term_load_multiple($tids = array(), array $conditions = array()) {
return entity_load_multiple('taxonomy_term', $tids, $conditions);
}
/**
* Load multiple taxonomy vocabularies based on certain conditions.
* Loads multiple taxonomy vocabularies based on certain conditions.
*
* This function should be used whenever you need to load more than one
* vocabulary from the database. Terms are loaded into memory and will not
* require database access if loaded again during the same page request.
*
* @see entity_load()
* @see entity_load_multiple()
*
* @param $vids
* @param array|bool $vids
* An array of taxonomy vocabulary IDs, or FALSE to load all vocabularies.
* @param $conditions
* @param array $conditions
* An array of conditions to add to the query.
*
* @return
* @return array
* An array of vocabulary objects, indexed by vid.
*/
function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array()) {
return entity_load('taxonomy_vocabulary', $vids, $conditions);
function taxonomy_vocabulary_load_multiple($vids = array(), array $conditions = array()) {
return entity_load_multiple('taxonomy_vocabulary', $vids, $conditions);
}
/**
* Return the taxonomy vocabulary entity matching a vocabulary ID.
*
* @param $vid
* @param int $vid
* The vocabulary's ID.
*
* @return TaxonomyVocabulary|false
......@@ -994,8 +994,7 @@ function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array(
* @see taxonomy_vocabulary_machine_name_load()
*/
function taxonomy_vocabulary_load($vid) {
$vocabularies = taxonomy_vocabulary_load_multiple(array($vid));
return reset($vocabularies);
return entity_load('taxonomy_vocabulary', $vid);
}
/**
......@@ -1011,8 +1010,8 @@ function taxonomy_vocabulary_load($vid) {
* @see taxonomy_vocabulary_load()
*/
function taxonomy_vocabulary_machine_name_load($name) {
$vocabularies = taxonomy_vocabulary_load_multiple(NULL, array('machine_name' => $name));
return reset($vocabularies);
$result = entity_load_multiple('taxonomy_vocabulary', FALSE, array('machine_name' => $name));
return reset($result);
}
/**
......@@ -1028,8 +1027,7 @@ function taxonomy_term_load($tid) {
if (!is_numeric($tid)) {
return FALSE;
}
$term = taxonomy_term_load_multiple(array($tid), array());
return $term ? $term[$tid] : FALSE;
return entity_load('taxonomy_term', $tid);
}
/**
......
......@@ -1362,7 +1362,7 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
$this->createTerm($vocabulary);
}
// Load the terms from the vocabulary.
$terms = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid));
$terms = taxonomy_term_load_multiple(FALSE, array('vid' => $vocabulary->vid));
$count = count($terms);
$this->assertTrue($count == 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
......@@ -1382,7 +1382,7 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
$this->assertFalse($deleted_term);
// Load terms from the vocabulary by vid.
$terms4 = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid));
$terms4 = taxonomy_term_load_multiple(FALSE, array('vid' => $vocabulary->vid));
$this->assertTrue(count($terms4 == 4), 'Correct number of terms were loaded.');
$this->assertFalse(isset($terms4[$deleted->tid]));
......
......@@ -261,28 +261,28 @@ function user_external_load($authname) {
}
/**
* Load multiple users based on certain conditions.
* Loads multiple users based on certain conditions.
*
* This function should be used whenever you need to load more than one user
* from the database. Users are loaded into memory and will not require
* database access if loaded again during the same page request.
*
* @param $uids
* An array of user IDs.
* @param $conditions
* @param array|bool $uids
* An array of user IDs, or FALSE to load all users.
* @param array $conditions
* (deprecated) An associative array of conditions on the {users}
* 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.
* @param $reset
* @param bool $reset
* A boolean indicating that the internal cache should be reset. Use this if
* loading a user object which has been altered during the page request.
*
* @return
* @return array
* An array of user objects, indexed by uid.
*
* @see entity_load()
* @see entity_load_multiple()
* @see user_load()
* @see user_load_by_mail()
* @see user_load_by_name()
......@@ -290,8 +290,8 @@ function user_external_load($authname) {
*
* @todo Remove $conditions in Drupal 8.
*/
function user_load_multiple($uids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('user', $uids, $conditions, $reset);
function user_load_multiple($uids = array(), array $conditions = array(), $reset = FALSE) {
return entity_load_multiple('user', $uids, $conditions, $reset);
}
/**
......@@ -306,52 +306,51 @@ function user_load_multiple($uids = array(), $conditions = array(), $reset = FAL
* @link http://drupal.org/node/218104 Safely impersonating another user @endlink
* for more information.
*
* @param $uid
* @param int $uid
* Integer specifying the user ID to load.
* @param $reset
* @param bool $reset
* TRUE to reset the internal cache and load from the database; FALSE
* (default) to load from the internal cache, if set.
*
* @return
* @return object
* A fully-loaded user object upon successful user load, or FALSE if the user
* cannot be loaded.
*
* @see user_load_multiple()
*/
function user_load($uid, $reset = FALSE) {
$users = user_load_multiple(array($uid), array(), $reset);
return reset($users);
return entity_load('user', $uid, $reset);
}
/**
* Fetch a user object by email address.
* Fetches a user object by email address.
*
* @param $mail
* @param string $mail
* String with the account's e-mail address.
* @return
* @return object|bool
* A fully-loaded $user object upon successful user load or FALSE if user
* cannot be loaded.
*
* @see user_load_multiple()
*/
function user_load_by_mail($mail) {
$users = user_load_multiple(array(), array('mail' => $mail));
$users = entity_load_multiple('user', FALSE, array('mail' => $mail));
return reset($users);
}
/**
* Fetch a user object by account name.
* Fetches a user object by account name.
*
* @param $name
* @param string $name
* String with the account's user name.
* @return
* @return object|bool
* A fully-loaded $user object upon successful user load or FALSE if user
* cannot be loaded.
*
* @see user_load_multiple()
*/
function user_load_by_name($name) {
$users = user_load_multiple(array(), array('name' => $name));
$users = entity_load_multiple('user', FALSE, array('name' => $name));
return reset($users);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment