Jump to content
gebeer

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...

Share this post


Link to post
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

Share this post


Link to post
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??

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

have you tried setting the get var programmatically in the module (e.g. $input->get->id = $this->user->id)?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By neonwired
      I'm hoping someone has seen this before. There doesn't appear to be an issue with the user info.

       

    • By Robin S
      A new module that hasn't had a lot of testing yet. Please do your own testing before deploying on any production website.
      Custom Paths
      Allows any page to have a custom path/URL.
      Screenshot

      Usage
      The module creates a field named custom_path on install. Add the custom_path field to the template of any page you want to set a custom path for. Whatever path is entered into this field determines the path and URL of the page ($page->path and $page->url). Page numbers and URL segments are supported if these are enabled for the template, and previous custom paths are managed by PagePathHistory if that module is installed.
      The custom_path field appears on the Settings tab in Page Edit by default but there is an option in the module configuration to disable this if you want to position the field among the other template fields.
      If the custom_path field is populated for a page it should be a path that is relative to the site root and that starts with a forward slash. The module prevents the same custom path being set for more than one page.
      The custom_path value takes precedence over any ProcessWire path. You can even override the Home page by setting a custom path of "/" for a page.
      It is highly recommended to set access controls on the custom_path field so that only privileged roles can edit it: superuser-only is recommended.
      It is up to the user to set and maintain suitable custom paths for any pages where the module is in use. Make sure your custom paths are compatible with ProcessWire's $config and .htaccess settings, and if you are basing the custom path on the names of parent pages you will probably want to have a strategy for updating custom paths if parent pages are renamed or moved.
      Example hooks to Pages::saveReady
      You might want to use a Pages::saveReady hook to automatically set the custom path for some pages. Below are a couple of examples.
      1. In this example the start of the custom path is fixed but the end of the path will update dynamically according to the name of the page:
      $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'my_template') { $page->custom_path = "/some-custom/path-segments/$page->name/"; } }); 2. The Custom Paths module adds a new Page::realPath method/property that can be used to get the "real" ProcessWire path to a page that might have a custom path set. In this example the custom path for news items is derived from the real ProcessWire path but a parent named "news-items" is removed:
      $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'news_item') { $page->custom_path = str_replace('/news-items/', '/', $page->realPath); } }); Caveats
      The custom paths will be used automatically for links created in CKEditor fields, but if you have the "link abstraction" option enabled for CKEditor fields (Details > Markup/HTML (Content Type) > HTML Options) then you will see notices from MarkupQA warning you that it is unable to resolve the links.
      Installation
      Install the Custom Paths module.
      Uninstallation
      The custom_path field is not automatically deleted when the module is uninstalled. You can delete it manually if the field is no longer needed.
       
      https://github.com/Toutouwai/CustomPaths
      https://modules.processwire.com/modules/custom-paths/
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By AndZyk
      Hello,
      I am currently building a intranet which will be hosted on the local network of a company. This intranet has many links to files on their fileserver with the protocol file://.
      So for example the links look like this file://domain.tld/filename.ext
      When I try to insert such a link into a URL field, I get the error, that only the protocol http:// is allowed. When I try to insert such a link into a CKEeditor link, it gets stripped out. Is it possible to insert such links into the FieldType URL and CKEditor.
      I know that I could use a FieldType Text or insert a RewriteRule in the .htaccess file, but I am looking for a more elegant solution. 😉
      Regards, Andreas
    • By lenoir
      Is it possible to let people edit a page without having to have a user-role?
      My case is the following:
      Visitors fill in a form (Formbuilder) which is saved to pages. They get a confirmation email which could contain a unique editing link. In case they need to update some information, they can click on this link, edit the fields and save. 
      Am I totally off? Is there a better practice? 
×
×
  • Create New...