Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
There does not appear to be a field_info function for retrieving all the instances of a given field. Or am I missing it?
Comment | File | Size | Author |
---|---|---|---|
#6 | field-info-bundles-370037-6.patch | 3.84 KB | bjaspan |
#4 | field-info-bundles-370037-4.patch | 3.58 KB | bjaspan |
#2 | field-info-bundles-370037-2.patch | 1.53 KB | bjaspan |
Comments
Comment #1
yched CreditAttribution: yched commentedTrue. field_info_instances() takes a $bundle_name, so we would need to find a different name - field_info_instances_of_field($field_name) or something
The information of instances of a $field is not compiled by _field_info_collate_fields() (instances are keyed by bundle name first).
1) we have _field_info_collate_fields() gather both informations and field_info_instances_of_field($field_name) can read from $info['instances_by_field']
2) we have field_info_instances_of_field($field_name) build from the existing $info['instances'] and loop on bundles to find the right $field_name.
1) doubles the size of the cached information, 2) adds (probably minimal) CPU cost on each call
I guess I'd go with 2)
Comment #2
bjaspan CreditAttribution: bjaspan commentedHow about this? _collate_fields stores an extra element in each field structure, 'bundles', an array of the bundle names for which instances of the field exist. Takes minimal storage space and no extra cpu. If all you want is a count of instances per field, a count of bundles is the same. If you actually want the instances, it is easy to iterate over field_info_instance().
Comment #4
bjaspan CreditAttribution: bjaspan commentedThere is NO WAY this patch caused a test failure, and the tests all pass after cvs update on my system, so I have no idea why the 1 test failed for the last patch.
New patch is the same as the old one with improved phpdoc.
Comment #5
yched CreditAttribution: yched commented+1, and tests work for me too.
Comment #6
bjaspan CreditAttribution: bjaspan commentedRe-rolled and removed double-spaces after periods.
Comment #7
webchickSorry! Thought I'd committed this already.
Done. :)