Current user as default for 'schema.Choice' ( Plone 6 Classic / xml )

Is it possitble to set 'default user' in XML for a choice field?
I want the default value to be 'current user'

<field name="select_user" type="zope.schema.Choice">

What happens when you insert a <defaultFactory>mypackage.myFunction</defaultFactory> element
with the dotted name of your custom value provider as the parameter?

See Dexterity XML — Plone Documentation v4.3 - this should still work...

Should probably work (but I need to figure out 'what is expected for default ' (user id or something else).

That said: I assume there must be something avalable already (isnt this used 'many other places' ?

Something like this should work (I think using something else than plone.api is faster, and the check for 'Authenticated' feels a bit strage (done to avoid errors with zope users). Probably dont need to be 'ContextAware' either.


from zope.interface import provider
from zope.schema.interfaces import IContextAwareDefaultFactory
from plone import api


def getUserId(context):
    current_user = api.user.get_current()
    user_groups =  current_user.getGroups()
    if 'AuthenticatedUsers' in user_groups:
    return None