Find entity field order and display names in code In PHP code, in Drupal 8, how can I get the display names and the order of entity fields to be displayed in a particular view mode.  I'm specifically trying to get the order of fields in node and paragraphs entities.

I've tried inspecting the node object, using the serializer service and REST interface.  I can find the fields and data, but not this metadata.
In Drupal, the display of fields is controlled by display mode configuration entities, which define the configuration for field formatters and the such.

You cannot get this metadata by viewing the node itself (or other entity). You would have to load the display mode for it.

The config object is entity_view_display and may be accessible over RESTful endpoints. An example output (in YAML) looks like so:


content:
  body:
    type: text_default
    weight: 0
    label: hidden
    settings: {  }
    third_party_settings: {  }
    region: content
  variations:
    type: commerce_add_to_cart
    weight: 1
    label: hidden
    settings:
      default_quantity: '1'
      combine: true
      show_quantity: false
    third_party_settings: {  }
    region: content
hidden:
  created: true
  stores: true
  uid: true