function entity_test_entity_getter in Entity API 7
Getter callback for the 'reference' property.
1 string reference to 'entity_test_entity_getter'
- entity_test_entity_property_info_alter in tests/
entity_test.module - Implements hook_entity_property_info_alter() for testing an property of type 'entity'.
File
- tests/
entity_test.module, line 262 - Test module for the entity API.
Code
function entity_test_entity_getter($node) {
if (empty($node->entity)) {
$node->entity = array(
'type' => 'user',
'id' => $node->uid,
);
}
// We have to return the entity wrapped.
// Special handling for anonymous user.
if ($node->entity['type'] === 'user' && empty($node->entity['id'])) {
return entity_metadata_wrapper('user', drupal_anonymous_user());
}
else {
return entity_metadata_wrapper($node->entity['type'], $node->entity['id']);
}
}