Editing content of virtual user pages

I have created virtual user pages on my website. I use these user pages to display information about users in the frontend.

Since this is a website with users from several countries, I use these virtual user pages also in the backend, to display the users from these different countries exclusively to their respective „country editors“ (with pages sections filtered by country).

What I have not yet been able to do is, to allow the country editors to edit the data of the users from their country. I can display the data of the individual user pages with the same fields blueprint as the users

https://my.website/panel/pages/intern+members+ZQ5abtQD (URL virtual user page)

https://my.website/panel/users/ZQ5abtQD (URL user profile)

However, when I edit the user data and try to save them, these changes are not saved.

I also had a route in mind, to forward the country editor from the virtual user page to the user profile and do the changes there.

	[
		'pattern' => 'panel/pages/intern+members+(:alphanum)',
		'action' => function ($alphanum) {
			return go('panel/users/$alphanum');
		}
	],

But that doesn’t work.

I probably have to do as described in the recipe “Virtual content from a database.”

and replace the WriteContent() statement in a page model for user pages. However, I read in this forum thread that the WriteContent() statement is deprecated in Kirby 5.

I´m a little bit stuck now. Has anybody an idea, how to proceed?

Thanks in advance

Thomas

Addendum, to clarify my goal:

My main goal is to filter user accounts by country and display them exclusively to their respective country editors in the panel for editing if necessary.

Perhaps my approach of filtering via the virtual user pages, which I already have for the front end anyway, is completely wrong.

Would a panel area be a better way to go?

Asked Claude the same question, got 4 approaches including complete code back:

  1. Custom Panel Area
  2. Hook to Save User Data from Virtual Pages
  3. Fix for my route trial
  4. Save logic for my “member” page model

I opted for option 4. Works great! It’s quite simple, once you see how it’s done. :wink:

// site/models/member.php
class memberPage extends Page
{
  public function update(array $input = null, string $languageCode = null, bool $validate = false): static
    {
      // Get the actual user
      $user = kirby()->user($this->slug());

      if ($user) {
          // Update the user instead of the page
          $user->update($input);
      }
    
    // Don't call parent::update() as we don't want to save the page
    return $this;
  }

}