I have a custom entity type with a set of base fields and I can create/view/update/delete entities. However When I create & enabled a custom view mode to the entity type and set to display subset of fields (using Manage display) in a page using below code:
$view_builder = $this->entityTypeManager->getViewBuilder('my_entity');
$build['top_summary'] = $view_builder->view($entity, 'summary');
The fields get rendered, but not in the order they are in the view mode. They are in the order of the IDs of the fields alphabetically. So if the entity has these fields in this order:
- First name
- Last name
They get displayed as
- First name
- Last name
I can hide fields using the hidden section, but can't change the visible fields' order.
Updating the fields' order in core.entity_view_display.[ENTITY_TYPE].[BUNDLE].[VIEW MODE]
does not help as the fields are sorted alphabetically on config import/export