Jump to content

PW3 - Automatically Add Field Value on Page Creation


ridgedale
 Share

Recommended Posts

Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.

I am trying to create a process whereby when a user logs in to their profile page (the user is automatically redirected to their profile page on login) and they then go to their 'members' page and creates a child page ('club-member'), the data stored in the user template ($user->usercode) is automatically added to the equivalent field on the club-member page.  This will be applicable only to the template used for the 'club-member' pages. Once the new page has been created the equivalent 'usercode' field on the 'club-member' page should not be subsequently editable.

Below is the page hierarchy for visual reference:

Login (home)

    |__  profile

                |__  members

                               |__  club-members

It seems like an AddHookBefore might be the solution here such as:

wire()->addHookBefore("Pages::saveReady", function($event) {
	$page = $event->arguments(0);
	if($page->template == 'club-member') {
        $clubcode = $user->club_code; 
        $field = $page->club_code;
        $field->set('value', $clubcode);
	}
});

I am I on the right track or is there a better way to achieve this?

Any thoughts appreciated.

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

×
×
  • Create New...