Hello,
I've got users this way:
user01
user02
...
user99
And I've got a template "Verkaeufergruppen" with the fields "title" and "bezei" this way
01 Adams
02 Brown
03 Smith
The rule is: user01 = 01 Adams, user02 = 02 Brown.
When a new page with the template "Bericht" is created:
The field "ADM_Name" (=text) should be set automatically to "Adams" if user01 has created the page.
That's why I use the PHP function substr, so user01 --> 01, user02 --> 02, ...
I made a hook in ready.php:
$wire->addHookAfter('Pages::saveReady', function($event) {
$page = $event->arguments(0);
if($page->template != "Bericht") return;
$admnr = substr($user->name, 4, 2);
$admname = $pages->findOne("template=Verkaeufergruppen, title=$admnr")->bezei;
if(trim($page->ADM_Name) == '') $page->ADM_Name = $admname;
But it doesn't work. I seems it's not possible to take "$user->name".
Perhaps somebody can help
Many thanks.