Jump to content

$user->name in a hook for pages


Reflexa
 Share

Recommended Posts

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...