How do I find out which base fields are available for an entity type? If I have an entity type id as a string, how I can tell which base fields are defined for that entity type?

For example, how do I programatically check that an entity type has the "changed" field?
How to get the base fields for an entity type id:

$base_fields = \Drupal::entityManager()-&gt;getBaseFieldDefinitions($entity_type_id);


You get an array. The keys are the field names. Example how to loop through this array:

foreach ( $base_fields as $field_name =&gt; $definition ) {
  echo "$field_name: ", $definition-&gt;getDescription(), "\n";
}


Edit:

The method has moved to the service EntityFieldManager:

$base_fields = \Drupal::service('entity_field.manager')
  -&gt;getBaseFieldDefinitions($entity_type_id);