Get the real order of schema fields

I have a client that wants some functionality where the data is processed 'in the same order as the add/edit forms'. zope.schema.getFieldNamesInOrder apparently only gives the original order of fields as defined in the schema, and not after processing directives like order_before, order_after. As far as I can tell there is no utility function to get the actual order of the schema, behaviors and all?

This is a really hacky way that seems to work

class WebProjectSchema(AutoExtensibleForm, form.Form):
    schema = IWebProject
class SomeOtherClass(BrowserView):
    def get_field_names(self):
        view = WebProjectSchema(context=self.context, request=self.request)
        view.updateFields()
        fields = [f for f in self.fields]
        for group in self.groups:
            fields.extend([f for f in group.fields])
        return fields

I say hacky because it seems a bit silly to have to define that class and process the entirety of its fields just to get that order.

I guess it's a matter of perspective. I would think of the order defined in the schema as the "actual" order, and the order that takes the directives into account as a special feature provided by plone.autoform.

I say hacky because it seems a bit silly to have to define that class and process the entirety of its fields just to get that order.

plone.restapi uses a similar approach when serializing a schema as a JSON schema: plone.restapi/src/plone/restapi/types/utils.py at main · plone/plone.restapi · GitHub

It is a bit silly, and could be avoided if someone would like to do the work to implement the same logic that currently exists in plone.autoform/plone/autoform/base.py at master · plone/plone.autoform · GitHub without depending on the existence of a z3c.form form.