pout Posted October 23, 2018 Share Posted October 23, 2018 Hallo, I tried to hook the adding of a new User to get a new subpage saved as a sort of user directory. But I didn't get it. First I tried Page::saved in ready.php (limitation on User-page ist missing). I want to get the name of the user added before and save a page under /Abos with the user-name as page title.: wire()->addHookAfter('Page::saved', function($event) { $savedUser = $event->object; $userpage = wire('pages')->find("parent=Abos, name=".$savedUser->name); if ( count($userpage) == 0 ) { $page = new Page(); $page->template = 'Abos'; $page->parent = wire('pages')->get('/Abos'); $page->title = $savedUser->name; $page->save(); } }); but this leads in never stopping new added pages under /Abos. Then I tried the same code with: wire()->addHookAfter('User::added', function($event) { That doesn't work. Hints appreciated. Thanks. Link to comment Share on other sites More sharing options...
elabx Posted October 23, 2018 Share Posted October 23, 2018 You are getting into a looping issue because you are hooking into every page saved. I also think you have to hook into Pages which then has the need info in its arguments. wire()->addHookAfter('Pages::saved', function($event) { $page = $event->arguments(0); if($page->template == "user"){ $savedUser = $page; $userpage = wire('pages')->find("parent=Abos, name=".$savedUser->name); if ( count($userpage) == 0 ) { $page = new Page(); $page->template = 'Abos'; $page->parent = wire('pages')->get('/Abos'); $page->title = $savedUser->name; $page->save(); } } }); 3 Link to comment Share on other sites More sharing options...
pout Posted October 24, 2018 Author Share Posted October 24, 2018 Great. Many thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now