1 field_test.entity.inc | field_test_entity_test_load($ftid, $ftvid = NULL) |
Loads a test_entity.
Parameters
$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.
Return value
The loaded entity.:
File
- core/
modules/ field/ tests/ field_test/ field_test.entity.inc, line 240 - Defines an entity type.
Code
function field_test_entity_test_load($ftid, $ftvid = NULL) {
// Load basic structure.
$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');
foreach ($entities as $key => $entity) {
$entities[$key] = entity_create('test_entity', (array) $entity);
}
// Attach fields.
if ($ftvid) {
field_attach_load_revision('test_entity', $entities);
}
else {
field_attach_load('test_entity', $entities);
}
return $entities[$ftid];
}