4

How to retrieve a list of fields, similar to what is available at admin/reports/fields, but so that I can have them in an array that I can stuff in a select dropdown.

8

You should use field_info_fields(), which returns an array containing information about all the defined fields. Its output is similar to the following one.

screenshot

  • What tools did you use to display the array in this format? :) – Mario Awad Sep 20 '12 at 8:51
  • 2
    You can use the Devel module from drupal.org/project/devel eg in a custom module dpm(field_get_fields());. Devel also has a Fields information block where it lists out basically the same information as the above 1 line of code. – tenken Sep 21 '12 at 14:41
2

You can also use field_info_field_map() it returns a lightweight map of fields across bundles. field_info_fields() also return fields list but its document suggesting us "Use of this function should be avoided when possible, since it loads and statically caches a potentially large array of information.".

The function only returns active, non deleted fields.

$field_list = field_info_field_map();

dsm($field_list);

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.