I want to retrieve all fields that entities are using (including locked fields).
How can I get a list of fields that are used in entities?
Like we get in admin/reports/fields.
I would recommend EntityFieldManager::getFieldMap. The EntityManager is only a service to provide functions from other classes.
array An array keyed by entity type. Each value is an array which keys are field names and value is an array with two entries:
- type: The field type.
- bundles: An associative array of the bundles in which the field appears, where the keys and values are both the bundle's machine name.
EntityFieldManagerInterface::getFieldMap() produces a keyed array by entity type > field name with further information on the field type and its associated bundles.
$field_map = \Drupal::entityManager()->getFieldMap(); $node_field_map = $field_map['node']; $node_fields = array_keys($node_field_map['node']);
EntityFieldManagerInterface::getFieldDefinitions() if you want further field metadata. It produces an array of
FieldConfig objects that you can parse through for further detail.