8

I wonder if there is a good, and easy way to get all fields of an entity.

I have a taxonomy vocabulary. Its terms have a special field I want to make list in a select box in one of my modules, so that users can select a special value of the term. Therefore, I need a way to list the possible fields for this term.

3 Answers 3

12

The function you are looking for is field_info_instances().

Retrieves information about field instances.

4

Drupal 7

You may try:

  $info = entity_get_property_info($entity_type);
  $info += array(
    'properties' => array(),
    'bundles' => array(),
  );
  // Add all bundle properties.
  foreach ($info['bundles'] as $bundle => $bundle_info) {
    $bundle_info += array('properties' => array());
    $info['properties'] += $bundle_info['properties'];
  }
  var_dump($info['properties']);

Or if you have Entity module installed, then try:

entity_get_all_property_info('node');

Drush commands (one of these):

drush eval "var_dump(entity_get_all_property_info('node'));"
drush eval "print var_export(array_keys(entity_get_all_property_info('node')));"
2

Can also use the function : field_info_field_map()

In place of returning entities going down to fields, it starts from field and go down to entities. That second one is fine to see where fields are going, whereas field_info_instances() shows how entities are built.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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