[support] D7: Loading full objects attached with Field API?
Georg Jaehnig
georg at jaehnig.org
Sat Sep 29 14:36:01 UTC 2012
Hi,
I have a question about loading fields attached to an entity.
I have a field called 'field_custom_namespaces' attached to the user
entity. field_custom_namespaces is a taxonomy term reference. Whats
the best and shortest code to load all the attached field objects,
i.e. term objects?
Currently I do it that way which seems totally bloated:
global $user;
$user = entity_load_single("user", $user->uid);
if (!empty($user->field_custom_namespaces)) {
$namespace_ids_wrapped = $user->field_custom_namespaces['und'];
} else {
$namespace_ids_wrapped = array();
}
foreach ($namespace_ids_wrapped as &$namespace_id_wrapped) {
$namespace_id_wrapped = $namespace_id_wrapped['tid'];
}
$namespaces = taxonomy_term_load_multiple($namespace_ids_wrapped);
So is there an easier, maybe "official" way with a proper function?
--
Georg | http://serchilo.net - command the web
More information about the support
mailing list