Get the custom fields created for User entity in Drupal8 I was trying to get the custom fields created for User entity in Drupal8:

Drupal::service('entity_field.manager')-&gt;getFieldStorageDefinitions('user') is returning all the fields

Drupal::service('entity_field.manager')-&gt;getFieldDefinitions('user', '') is returning only the default fields

Was doing a diff of the 2 arrays, but I was wondering if there is a proper way to achieve this?
You can filter the fields by checking which interface the field implements:

$fields = array_filter(
  \Drupal::service('entity_field.manager')-&gt;getFieldDefinitions('user', 'user'),
  function ($fieldDefinition) {
    return $fieldDefinition instanceof \Drupal\field\FieldConfigInterface;
  }
);


The second parameter of getFieldDefinitions() is the bundle. The user entity doesn't have bundles, but you can configure bundle fields. In this case the bundle name defaults to the entity id.