Add 'Current User' Default Option to User Field


#1

Currently, we can explicitly name an existing user as the default for a ‘user’ field - like this:

fields:
  author:
    label: Author
    type: user
    default: john

However, the most common use-case is to actually have the field default to the currently logged-in user - that is: whoever is logged in is who is most likely to be writing the article, not an arbitrary user.

Unfortunately, there is no way to set such a default for a user field - it’s either leave it empty, or have an explicit user. What we need is to be able to do:

fields:
  author:
    label: Author
    type: user
    default: current

#2

You could use this custom author field (copy file to site/fields/author/author.php): https://gist.github.com/distantnative/f3918ca69173dd38fbd8


#3

Thank you, @distantnative! - will have a look at it, for sure! :smile:


#4

gist is missing. how to do it?


#5

I think you can do it with the default user field now:

user:
  type: user

#6

Thanks, very helpful.