Programmatically, in Drupal 8, how can I retrieve a list of all entity reference fields including label and machine name?

I have tried the entity manager service, but it only produces a list of keys without their label, and it is reported to be deprecated.

1 Answer 1


If something is deprecated then that means there is always an explicitly documented replacement and a change record with code examples.


In this case it's the EntityFieldManager/entity_field.manager service. But neither entity.manager nor entity_field.manager provide just field names, both provide a list of field definitions.

As always, share your code and you get more specific answers.

One thing you need to be aware of in regards to labels is that there are field storages (fields in 7.x terms) and fields (field instances in 7.x). A single field storage (= unique field name) can exist on different bundles/node types with different names. So one approach to do what you want would be to start with the field map for your type, then loop over the bundles for each field to get the field definition and that label.

Your Answer

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

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