lowlines Posted August 7, 2013 Share Posted August 7, 2013 I'm working on a redirect module which allows admins to set what happens when they submit a form in the back-end, (ie clicking "Install" on a module automatically returns them to the modules page, or clicking "Save" on virtually any admin page will redirect to the parent listing page). What I also want to do is when you go to create a new page it will auto-publish it instead of setting the status to Unpublished, forcing the user to go into the page and click publish before it is visible on the front-end or to navigation. I understand the reasoning behind the initial Unpublished state however I want to have the auto-publish functionality for the instance where you may have a sitemap with more than a dozen or so pages and you want to just push out the whole site structure for staging purposes so someone else can go in and add the content later. I tried using code based upon this thread (http://processwire.com/talk/topic/4180-cant-bulk-publish-unpublished-pages/) however I would say I am trying to apply it at the wrong point in time. Currently I am doing all my redirect logic after the Session:redirect hook. I've tried Googling for the correct hook for directly AFTER a page is created (thus editable), but to no avail. Link to comment Share on other sites More sharing options...
adrian Posted August 7, 2013 Share Posted August 7, 2013 Hi lowlines and welcome to PW. Not sure if you have seen this module or not: http://modules.processwire.com/modules/after-save-actions/ but it allows you to control what happens after a page is saved. Not sure exactly what would be your best option, but you should be able to hook into before save, eg: $this->pages->addHookBefore('save', $this, 'setPublished'); The setPublished function would then remove the unpublished status for the page. Does that help at all? Also, have you seen: http://processwire.com/api/hooks/ http://processwire.com/api/hooks/captain-hook/ EDIT: Have a read of this: http://processwire.com/talk/topic/2331-doing-additional-logic-after-saving-a-new-page/?p=21881 Talks about doing additional logic after saving a new page and so I think might suit your needs. Might be the addHookAfter('added' that you are looking for, although do you really want to publish a page that has just been created and still only has a title and name field assigned? 3 Link to comment Share on other sites More sharing options...
lowlines Posted August 7, 2013 Author Share Posted August 7, 2013 Thanks adrian that's exactly what I needed. My module is based upon AfterSaveActions but extends what it does to other parts of admin. To answer your question, auto-publishing would likely only be used during the initial site setup where the client isn't doing the majority of the page creation. Often I have a sitemap before the actual content so it is better to at least get the structure setup rather than the whole process getting bottlenecked. Then once the site is at a complete enough stage we would toggle off auto-publishing so clients can create any future pages without them automatically going live. In the early stages, the less button clicks / steps required to do something the better! 1 Link to comment Share on other sites More sharing options...
teppo Posted August 7, 2013 Share Posted August 7, 2013 @lowlines: you're probably already aware of this, but if you've got a sitemap planned out already and just want to quickly create matching pages, Batcher is very helpful for stuff like that. You should check it out if you haven't already. 4 Link to comment Share on other sites More sharing options...
ryan Posted August 9, 2013 Share Posted August 9, 2013 I think that some code like this in your /site/templates/admin.php would probably solve it. I haven't tried it (just wrote it in the forum), but I think it would work. $pages->addHook('saveReady', null, 'hookSaveReady'); function hookSaveReady($event) { $page = $event->arguments(0); if($page->id) return; // not a new page if(!$page->is(Page::statusUnpublished)) return; // page is already published $admin = wire('pages')->get(wire('config')->adminRootPageID); if($page->parents->has($admin)) return; // leave pages in admin alone $page->removeStatus(Page::statusUnpublished); // remove unpublished status. } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now