How to get the list of fields available in the user entity I have created a custom field to allow users to set their privacy settings based on the fields attached into their account.

I would like to get the list of fields available in the user entity so that I can create a table select form where the users can select the permission per field based on account type.

How to do it in a custom field?

Here's my curreny code:

  namespace Drupal\privacy_settings\Plugin\Field\FieldType;

  /**
   * @FieldType(
   *   id = "privacy_settings",
   *   label = @Translation("Privacy Settings"),
   *   description = @Translation("Privacy Settings"),
   *   default_widget = "privacy_settings_widget",
   *   default_formatter = "privacy_settings_formatter_default"
   * )
   */
  class PrivacySettingsField extends FieldItemBase {

  /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['value'] = DataDefinition::create('string')
      -&gt;setLabel(new TranslatableMarkup('@operation access', ['@operation' =&gt; 'Privacy Settings']));
    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [
      'columns' =&gt; [
        'value' =&gt; [
          'type' =&gt; 'blob',
          'size' =&gt; 'big',
          'serialize' =&gt; TRUE,
          'not null' =&gt; TRUE,
        ],
      ],
    ];
  }


  /**
   * {@inheritdoc}
   */
  public function setValue($values, $notify = TRUE) {
    if (isset($values['value']['table']['rows'])) {
      $values['value'] = serialize($values['value']['table']['rows']);
    }
    parent::setValue($values, $notify);
  }

  /**
   * {@inheritdoc}
   */
  public function isEmpty() {
    $value = $this-&gt;get('value')-&gt;getValue();
    return $value === NULL || $value === '';
  }


  /**
   * Return the list of operations available.
   *
   * @return array
   *   The list of operations.
   */
  public function getOperations() {
   return [
      t('Account Type 1'),
      t('Account Type 2'),
      t('Account Type 3')
    ];
  }

}
You can get user entity field definitions list by using the following code:

$user_field_definitions = \Drupal::service('entity_field.manager')
  -&gt;getFieldDefinitions('user', 'user');
// List of user field definitions.
dump($user_field_definitions);