Find target bundle(s) for a specific entityreference field I am creating a simple administration page that shows all content types and some details about each content type field.


I am getting the list of content types with node_type_get_types()
I am getting the list of fields with field_info_instances()


When the widget module is entityreference I'd like to display the target bundle(s) of that entity reference field.

foreach(node_type_get_types() as $value) {

  $fields = field_info_instances('node', $value-&gt;type);

  // Loop through fields
  foreach($fields as $field) {

    if ($field['widget']['module'] == 'entityreference') {

      // Get the target bundle(s) for this field
    }
  }
}


Thanks in advance for any help on that!
Drupal 8 version:

$bundles = \Drupal::entityManager()
-&gt;getAllBundleInfo()['node'];
 foreach ($bundles as $id =&gt; $value) {
 $node_fields = \Drupal::entityManager()
  -&gt;getFieldDefinitions('node', $id);
   foreach ($node_fields as $field) {
      if ($field instanceof \Drupal\field\Entity\FieldConfig) {
        if ($field-&gt;getType() == 'entity_reference') {
          $target_bundle = $field-&gt;getSettings()['handler_settings']['target_bundles'];
          kint($target_bundle);
        }
      }
    }
  }


With $target_bundle, You can do something like this as well to filter out a specific bundle:

if ($target_bundle != null &amp;&amp; key($target_bundle) == 'mybundle'){
  kint($field-&gt;id());
}