我已经看到了如何通过实体和捆绑随取领域的名单field_info_instances()
和field_info_field()
,但我没有看到一种方式来获得特定类型的所有领域。
我能够将其煮熟以做我想做的事情:
function field_get_fields_of_type($type) {
$fields_info = field_info_instances();
$return = array();
foreach ($fields_info as $entity => $bundles) {
foreach ($bundles as $bundle => $fields) {
foreach ($fields as $field_name => $info) {
$more_info_because_type_isnt_included = field_info_field($field_name);
if ( $more_info_because_type_isnt_included['type'] == $type) {
$return[$field_name] = $more_info_because_type_isnt_included;
}
}
}
}
return $return;
}
dpm(field_get_fields_of_type('entityreference')); // prints out all entityreference fields
但这似乎需要大量代码,并且需要进行大量循环操作才能获得可能应通过现场API到达的内容。
有人知道Field API函数可以更有效地检索我要查找的数据吗?