Jump to content

MiniRelease: ListAfterSave


Adam Kiss
 Share

Recommended Posts

Introduction

Enhancing my previous post about modifying pagesave routine, which resulted in Ryan's module [for both there is link, but I'm too lazy to look it up. Sorry], I took it a little bit further and created this mini-module. It has been actually finished for month, but after all, I'm lazy mofo.

What it does?

  • Redirects into list after saving a page.
  • Redirects into list after saving a field.
  • Redirects into list after saving a template.
  • If you click breadcrumbs above your page edit area, you're redirected into this page in your pagetree, rather than it's edit window.
  • All configurable [default: on all]

How to install

As mentioned, I'm lazy idiot, so instead of creating intelligent package or something, I added this file here [only]. Create folder 'ListAfterSave', Put this file there, refresh your modules and activate. Modify options, if you're picky idiot.

Legal notice

I created this. By downloading and/or installing this file, you agree that if anything goes wrong, you're an idiot and everything that may or may not include data loss is your fault.

Download

Attached to this post

OT

My feet really hurt, I've been doing sports.

Adam

ListAfterSave.module

Link to comment
Share on other sites

Nice job. Just tested this and looked at the code. This is very well put together! I also like how you made it configurable. Also, I tested and it works equally well in 2.0 and 2.1.

Your module is so nicely coded that I have one suggested optimization to make it even better. That would be to add more conditions before adding hooks. This is so that your hooks don't get added when they aren't applicable, like on the public side of the site, or when a user isn't logged in. Your module already accounts for that, but only after the hooks have already been put in place. Page::loaded can be an expensive hook (it gets called for every single page loaded in memory in the request, which could feasibly be hundreds of calls). So it's desirable to be selective about when you add a hook to it, as you can save some CPU cycles by not adding that hook when you don't need it.

The init() function can't tell anything about the current $page simply because modules are init'd before PW even tries to handle the page request. So a good strategy is to have your init() just determine if your hooks will possibly be useful to the current user. If it's a guest user, there's no point in even adding hooks. But if it's not a guest user, then your hooks may be useful, depending on what the current $page->process is. Since we can't tell anything about the $page yet from init(), just delay the decision till Page::render, like this:

<?php

public function init() {	

    // if there is no logged-in user, don't bother continuing
    if($this->user->isGuest()) return;

    // if the user is logged in, add a hook before Page::render
    // which will determine whether to add more hooks
    $this->addHookBefore('Page::render', $this, 'pageRender');
}

public function pageRender(HookEvent $event) {

    // modules are init()'d before the page is loaded
    // so we couldn't check the value of page->process from init()
    // that's why we're doing it here instead. 

    // this checks to make sure that we are in the admin and on a Process we wish to hook
    if(in_array((string) $this->page->process, array('ProcessPageEdit', 'ProcessTemplateEdit', 'ProcessField'))) {

        // hook before a redirect occurs, so we can modify the redirect URL:
        $this->session->addHookBefore('redirect', $this, 'sessionRedirect');

        if($this->page->process == 'ProcessPageEdit') { 
            // hook after the page has been loaded and modify the breadcrumbs array
            $this->session->addHookAfter('Page::loaded', $this, 'breadcrumbsEdit');
        }
    }
}
Link to comment
Share on other sites

This is nice work, thanks Adam! I like to stay in edit views, but actually prefer "Redirect all breadcrumb links to list?" setting. And it might be that our clients will prefer different setting than I do, so this is great to have.

Link to comment
Share on other sites

@Apeisa: I'm not sure this setup allows different users to have different settings, unfortunately! But I will look into it!

@Ryan: Thanks, I will use this 'upgrades', if possible.

It looks that I'll maintaint this plugin after all! :)

Link to comment
Share on other sites

This is nice work, thanks Adam! I like to stay in edit views, but actually prefer "Redirect all breadcrumb links to list?" setting. And it might be that our clients will prefer different setting than I do, so this is great to have.

One more reason to like this setting: if you have some pages along the path that user doesn't have edit access (but has view access), then clicking on those pages will give him/her a empty page with warning: "You don't have access to edit this page".

Link to comment
Share on other sites

Apeisa: That might be some side accomplishment, at least I haven't tried that with non-supardamin users yet – since my last experiment with non-sa, ehich turned out to be not good at all (I missclicked something, haven;t been able to understand user settings and made a total mess out of access configuration in pages :D)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...