Jump to content

Process module - user edit page under custom URL


Recommended Posts

Hello,

I have a Process module with a user dashboard and I would like to have the user page edit screen at a custom URL 'myprofile'.
I cannot use the default profile edit page because it does not support tabbed interfaces.

The method for executing the user edit page from within my module looks like this

	public function ___executeMyprofile() {
	 
	    $processUser = $this->modules->get('ProcessUser');

	    return $processUser->executeEdit();

	}

The user edit screen displays when I go to /dashboard/myprofile. But the request is redirected several times and I end up at the URL /access/users/edit/?id=5522 which I wanted to avoid.

This happens because of this line in ProcessPageEdit.module.

I guess the solution lies in hooking into the ___loadPage() method from within my Process module. But, honestly, I have no clue on how to put the pieces together.
So I need some pointers on how to best achieve the goal of having the current user's edit page under a custom URL in the admin area, ideally in the scenario of a custom Process module.

Any help would be much appreciated.

EDIT:

I tried some variations of hooking like

	public function ___executeMyprofile() {
	 
		$this->addHookBefore("ProcessPageEdit::loadPage", $this, "interceptRedirect");
	    $processUser = $this->modules->get('ProcessUser');

	    return $processUser->executeEdit();

	}

	protected function interceptRedirect(HookEvent $event) {

	    $event->replace = true;

	    $event->return = $this->user;

	}

but the hook is not being executed at all. Also when placing the call to the hook in my Process module's init() method. Also when using an After hook and not replacing the hooked method. No luck so far...

Link to comment
Share on other sites

@benbyf good point. It is a process module that creates a custom page in the admin. I don't know if autoload also applies to those. But I tested and added

    'singular' => true,

    'autoload' => true,    

to the module's .info.php.

But same behaviour. The code in my hook method does not get executed and I still get redirected to /access/users/edit/?id=5522

Link to comment
Share on other sites

Soooo if I were making this I would create a module extending Process, after installation add an admin page in the page tree with a process of your module name. then when you access that page (maybe by adding a button somewhere in the nav with a specificed id of the user?) the module will be called and you can grab the id and do some stuff with it. 

or is it meant for users on the front end??

Link to comment
Share on other sites

@benbyf thank you for your input.

This is a process module called ProcessMemberDashboard that extends Process and it is for the backend. The module is built using the Hello Process Module Skeleton.

I already have a working dashboard that is rendered by this module in the admin. There is a page under Admin with template admin and my ProcessMemberDashboard process assigned.

Now I want to extend the module with the methods that I pasted in my first post to show the user edit screen from within my dashboard under the URL dashboard/myprofile.

The problem really is the redirection that is happening. And that I can't seem to hook into the ProcessPageEdit::loadPage method from within my module.

I just accidently found out that the hook is being called, when I open the URL access/users/edit/?id=5522 directly. Whereas it is not called when I open dashboard/myprofile which redirects me (through 4 redirect steps) to access/users/edit/?id=5522.

So for the moment I'm still lost...

Link to comment
Share on other sites

@gebeer, I don't want to be pouring cold water on this but I have a feeling this approach is unlikely to work. At least not without giving the role edit access to the 'user' template, and it seems like that would be a security liability. But if you do get this working then cool. :-)

I suggest opening a GitHub request/issue to add proper support for FieldsetTab to ProcessProfile. Whether it's a request or an issue depends maybe on whether you think support for FieldsetTab was deliberately left out of ProcessProfile or was just an oversight. If you ask the responders in the other thread to "thumbs up" the issue on GitHub then hopefully Ryan will give it some attention soon.

Until there is proper support in ProcessProfile you could consider if an accordion-style interface could be an okay substitute for a tabbed interface. You could change to closed Fieldsets instead of FieldsetTabs and then add a little JS so that only one Fieldset is open at a time (to keep the profile edit page from being overwhelming):

$wire->addHookAfter('ProcessProfile::execute', function($event) {
    $out = $event->return;
    $js = "
    $(function() {
        $('.InputfieldFieldsetOpen label').click(function() {
            if($(this).parent().hasClass('InputfieldStateCollapsed')) {
                $('.InputfieldFieldsetOpen:not(.InputfieldStateCollapsed)').children('label').find('.toggle-icon').trigger('click');
            }
        });
    });
    ";
    $out .= "<script>$js</script>";
    $event->return = $out;
});

You could stick with FieldsetTabs and adjust the JS to suit, but the open/close of the FieldsetTabs in ProcessProfile seems a little buggy to me (flickering, toggle icons in wrong state - not from the JS addition above, but untouched too).

  • Like 1
Link to comment
Share on other sites

@Macrura the page edit process already loads the correct page when I call

$processUser->executeEdit();

The problem is the redirection to accss/users/edit/&id=xxx that happens because of this line in ProcessPageEdit.module

@Robin S fortunately PW's role/permission system got me covered here. The user is a 'member' user with own user template and parent. They have edit permissions for member users only. I restrict them from editing other member users by using a hook to ProcessPageEdit::loadPage that redirects them to their own user edit page when they try to access another user's edit page. So no security issues here.

I was already thinking about making a feature request on github to support tabs in user profiles. Not too long ago I had opened a thread about this. It seems I'm not the only one who would need this.

Thanks for your suggestion and code for the accordion. But I really do need tabs here. Otherwise the edit form gets too confusing for users because there are more than 20 fields. I had a look at the ProcessProfile to see if I could add the tabs functionality through a hook. But this seems not possible. Would have to extend the class and overwrite the buildForm method. Better open that feature request...

But in the meantime it would be great to find a way around that redirection issue. I still don't understand why this  hook in my process module

public function ___executeMyprofile() {
	 
		$this->addHookBefore("ProcessPageEdit::loadPage", $this, "interceptRedirect");
	    $processUser = $this->modules->get('ProcessUser');

	    return $processUser->executeEdit();

	}

	protected function interceptRedirect(HookEvent $event) {

	    $event->replace = true;

	    $event->return = $this->user;

	}

is not called at all.

 

  • Like 1
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...