With http://getkirby.com/forum/panel/20150121/default-author-field-to-user-who-is-logged-in:
I have added the author field to my blog pages in the blueprint, but I want to set the default to the person, who is writing the blog article. That should come from the login.
How can I do that in the blueprint like „default: today“ in http://getkirby.com/forum/panel/20141108/get-current-date-in-panel/#20141121100749 for a date field?
Thanks for your help.
I am not aware of any built-in solution. What I am thinking could be a way is:
- Create a new custom form field: http://getkirby.com/docs/panel/custom-form-fields
- Could be based on the select field: https://github.com/getkirby/panel/blob/master/app/fields/select/select.php
- Add all users as select options by looping through
$users
: http://getkirby.com/docs/cheatsheet/#users
- Make the current user the pre-selected/default one by using
$user->isCurrent()
: http://getkirby.com/docs/cheatsheet/user/is-current
1 Like
Thanks for your topic, but I want to know, what I can add at my blueprint as an “built-in solution” like “default: today” at http://getkirby.com/forum/panel/20141108/get-current-date-in-panel/#20141121100749 …
And as I said, I don’t think that there is any built-in way to achieve this. That’s why I suggested a way to realize it without the needs to fill in an empty author text field.
But I agree, would be nice to have such a thing as a default option.
Something like this should work (at least it did in a quick test): https://gist.github.com/distantnative/f3918ca69173dd38fbd8
I only quickly threw it together, but it should be it more or less – still not ‘built-in’, but as a custom form field it’s as clean as it gets, if you actually need it.
Just put it as author.php
in site/fields/author/
and use in your blueprint type: author
1 Like
@distantnative:
Many thanks for your very nice work. It looks best.
I have tested it.
It works exactly the way I wanted it.
.
@bastianallgeier:
Do you include this in the next Kirby version?
With the last http://download.getkirby.com/nightly this field prevents the input from to be saved.
Something is wrong. 