diff options
Diffstat (limited to 'modules/field/field.info.inc')
-rw-r--r-- | modules/field/field.info.inc | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/modules/field/field.info.inc b/modules/field/field.info.inc index 8b273da6a..f229a1d39 100644 --- a/modules/field/field.info.inc +++ b/modules/field/field.info.inc @@ -507,14 +507,48 @@ function field_info_bundle_entity($bundle) { /** * Return array of all field data, keyed by field name. * + * @param $bundle_type + * (optional) The bundle type on which to filter the list of fields. In the + * case of nodes, this is the node type. + * @param $field + * (optional) A field array or name on which to filter the list. + * @param $field_type + * (optional) A field type on which to filter the list. * @return * An array of Field objects. Each Field object has an additional * property, bundles, which is an array of all the bundles to which * this field belongs. */ -function field_info_fields() { - $info = _field_info_collate_fields(); - return $info['fields']; +function field_info_fields($bundle_type = NULL, $field = NULL, $field_type = NULL) { + // Build the list of fields to be used for retrieval. + if (isset($field)) { + if (is_string($field)) { + $field = field_info_field($field); + } + $fields = array($field['field_name'] => $field); + } + elseif (isset($bundle_type)) { + $instances = field_info_instances($bundle_type); + $fields = array(); + foreach ($instances as $field_name => $instance) { + $fields[$field_name] = field_info_field($field_name); + } + } + else { + $info = _field_info_collate_fields(); + $fields = $info['fields']; + } + + // If a field type was given, filter the list down to fields of that type. + if (isset($field_type)) { + foreach ($fields as $key => $field) { + if ($field['type'] != $field_type) { + unset($fields[$key]); + } + } + } + + return $fields; } /** |