There was a discussion about the ordering for the Forms (view level). symfony/symfony#5827 which unfortunately ended without a consensus.
You can handle this in the template itself, but that only works if you control the template that is used. Which is not always the case, FormTypeExtensions adding additional forms and theming like the SyliusThemeBundle provides.
Which means that whenever you add additional forms or change the theme you need to update this at multiple places.
One of the suggested alternatives was to use a before/after option, which provides enough flexibility for this use-case.
And now my proposal:
$builder->add('name', FormType::class, ['position' => ['before', 'form-name']]);
Which in the finishView()
method is properly re-ordered for display.
The position
is a nested OptionResolver with at
, 'name', and 'priority' as options.
This merely a simplified usage with a normalizer.
Internally the following algorithm is used for re-sorting.
NOTE: This is a proof of concept, hasn't been worked-on further.