Loads a test_entity.
$ftid: The id of the entity to load.
$ftvid: (Optional) The revision id of the entity to load. If not specified, the current revision will be used.
The loaded entity.
function field_test_entity_test_load($ftid, $ftvid = NULL) {
// Load basic strucure.
$query = db_select('test_entity', 'fte', array())
->condition('fte.ftid', $ftid);
if ($ftvid) {
$query
->join('test_entity_revision', 'fter', 'fte.ftid = fter.ftid');
$query
->addField('fte', 'ftid');
$query
->addField('fte', 'fttype');
$query
->addField('fter', 'ftvid');
$query
->condition('fter.ftvid', $ftvid);
}
else {
$query
->fields('fte');
}
$entities = $query
->execute()
->fetchAllAssoc('ftid');
// Attach fields.
if ($ftvid) {
field_attach_load_revision('test_entity', $entities);
}
else {
field_attach_load('test_entity', $entities);
}
return $entities[$ftid];
}