eriks
October 13, 2019, 12:07pm
1
In my blueprint I can select an author via
fields:
author:
label: Author
type: users
And in my projects it saves like this:
Author:
- mail@outlook.de
Is there another way to store the authors Username without running scripts that deletes titles?
The usernames are unique and being used for searching.
texnixe
October 13, 2019, 12:16pm
2
Starting with 3.3.0, the user ID will be stored instead of the user email: https://github.com/getkirby/kirby/issues/1885
I’m not sure why it won’t be possible to store a custom value, maybe to make sure that a unique value is stored.
If you want to store something else, you could use a select/multiselect field instead of the users field.
eriks
October 13, 2019, 1:33pm
3
I’ve created a multiselect field:
authors:
type: multiselect
options: query
query: users
But it still saves the user with their mail…
I thought to use query: users.title
but that does not work. How can I get the Title(Name) of the users? If I select an author, it shows their name, and not their mail. That bothers me.
authors:
type: multiselect
options: query
query:
fetch: kirby.users
text: "{{ user.somefield }}"
value: "{{ user.somefield }}"
eriks
October 16, 2019, 11:46am
5
Hey I was thinking.
And looking at my search controller and couldn’t get behind the logic.
<?php
return function ($site) {
$query = get('q');
$results = $site->search($query, 'title|tags|place|headline|author');
return [
'query' => $query,
'results' => $results
];
};
at search($query, ‘…’); The controller looks into each title and has a ‘correct’ or ‘incorrect’ output. But since author is just a mail, can I somehow modify that it’ll convert the mail to a username? I do that in my frontend via
<?php $users = $page->author()->toUsers();
foreach($users as $user): ?>
<a href="<?= $site->url() ?>/authors/<?= $user->name()->slug() ?>"><?= $user->name() ?></a>
<?php endforeach ?>
Like that it’s a variable.
<?php
return function ($site) {
$query = get('q');
$author = $page->author()->toUsers();
[…]
$results = $site->search($query, 'title|tags|place|headline|author');
return [
'query' => $query,
'results' => $results
];
};
I just want to convert the mail into a name like I do in the frontend. If I would now use multiselect fields I would have to rewrite som much
The search method is not very bright, it only goes through each individual field stored in the content file and looks for matches. And of course if you look for something other than what is stored, it won’t find anything.
Your best bet would be either another field type (why would you have to rewrite that much?), or a custom search method (I think that will be more work).
Or use the future version 3.3.0 of Kirby:
@anon77445132 That won’t help if you search for the user name. Nobody will search for a random number.
Hello texnixe, I used this code which works very well.
I would like to know how to put by default the name of the user who is connected to the panel? (to have the same behavior as a type: users).
default: ACM
author:
type: multiselect
options: query
query:
fetch: kirby.users
text: "{{ user.firstname }} {{ user.namefamily }}"
value: "{{ user.firstname }} {{ user.namefamily }}"
default: ACM
max: 1
required: true
Why don’t you use the users field?
If I delete a user, I lose the name of the news author.
True. But I’m afraid you can’t use query language for the default value.
1 Like
What you could do, is store the current username via a hook or via a custom page model that overwrite the create
function.