Jan Romero Posted November 19, 2014 Share Posted November 19, 2014 So I suppose this is a somewhat pointless addition, seeing as drafts are about to come to the core, but I needed this right now and ProcessWire made it possible for me to implement over the last two days. An experience that convinced me once more that ProcessWire is absolutely amazing. GitHub link. So what does this do? This module allows you to create a draft version of (hopefully) any page, which can be edited while the public facing page remains in place and unchanged. Drafts are placed under a special Admin page, which also doubles as a rudimentary manager. It shows what pages have drafts assigned and lets you update the original page with its draft. I need all this mainly for front-end editing, so for me the focus is on the added API methods. I have added functionality to redirect every edit to a draft page for testing, and it can make sense to have that behavior of course, so it will probably become a config setting. How does it do that? Page cloning is very very handy for this purpose, so that’s mostly what I’m doing here. It’s elegant in that very little code is needed, but it is perhaps somewhat crude to delete pages, including their field data and files on the file system, so much. I needed some hacky-feeling tricks to convince PW to delete pages that have children and clone pages to my custom admin page even when their template prohibits that sort of parent. What doesn’t this do (well)? Since a draft is linked to its page by having the page ID for a name (!), which conviniently also guarantees uniqueness, modifying page names should be pretty much impossible. It would be best to create a table to store the references, but I kind of like that you can keep everything 100% PW API. The most complicated fieldtypes I have tested this module with are Images/Files and Multiplier. That covers my immediate need, but perhaps PageTables will cause problems. I don’t have any experience with those. There are probably a lot of other things to look out for, but I can’t remember any more right now. Be aware this is most definitely not production ready or anything. I would like to thankTeppo Koivula, whose Changelog module I used for inspiration downright based this on. Great work there, and a lot to learn from. If you find fragments of Changelog in this module, that’s no coincidence. Also hugely helpful are the great members of this forum and Ryan’s code, which I assume we all use as our main documentation <3 Please absolutely tear this apart, if you can spare the time to have a quick look. I like to think I did okay, but I’m eager to learn and I’m sure this is full of questionable practices, bugs and inefficiencies. So yeah, its unlikely anyone will have the need to use this on a site, but hopefully I can get some feedback out of it and perhaps it can teach other beginners like me a trick or two. GitHub link again. /wall of text 9 Link to comment Share on other sites More sharing options...
kongondo Posted November 19, 2014 Share Posted November 19, 2014 Hey Jan, cool 'experiment'! Even if this may become obsolete soon, I think it will be a useful learning tool for some of us and a nice toy to play with - so a great addition, thanks! Link to comment Share on other sites More sharing options...
Nico Knoll Posted November 20, 2014 Share Posted November 20, 2014 I guess repeaters aren't working? Or am I wrong? Link to comment Share on other sites More sharing options...
Jan Romero Posted November 21, 2014 Author Share Posted November 21, 2014 They aren’t. Although from the looks of it, it seems to be partly the repeaters’ fault?! Cloning a page also clones the repeater pages as expected, but for some reason they’re parented to page-id 0, so they don’t show up in the admin. Things quickly get sort of messy, but it shouldn’t be too hard to fix, actually. Link to comment Share on other sites More sharing options...
krisj Posted February 15, 2015 Share Posted February 15, 2015 I am struggling to get it to work. I install the module, see a new "Drafts Page" appera but after that I only get "You are NOT editig draft version..." eroor message when I edit pages. What am I missing? How do you clone/create a draft? sorry its late, I should in bed.... :/ 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted February 15, 2015 Author Share Posted February 15, 2015 Hi, a draft should be created automatically when editing a page, unless you are a superuser and/or have the permission “managedrafts”. If you see the new page in the admin menu, you're allowed to edit pages without having to make a draft first, so you're not redirected. Try logging in as a less privileged user. I'm doing a little overhaul at the moment, putting the draft relations into the database and adding a couple of things here and there. If you have any suggestions for the admin side, I'm all ears, because I'm not really using it that way, so I have no real direction.. Link to comment Share on other sites More sharing options...
krisj Posted February 16, 2015 Share Posted February 16, 2015 Thanks for the response! I was expecting to be able to literally create a draft version of the page to be able to work on the changes before making it live. It would be great to be able to just click a "Save Draft " if the user has "managedrafts" permission. at the moment the module assumes the draft creators and publishers are 2 separate and exclusive roles. Approvers/publishers can not create drafts themselves and draft creators cannot publish. Perhaps it needs another role/-s? nice work though! 1 Link to comment Share on other sites More sharing options...
krisj Posted February 16, 2015 Share Posted February 16, 2015 Just thinking about it and at the moment the module is more like a mandatory approval system. Where's it would be nice to have a more granular workflow. Example roles: create draft / save as draft manage drafts (view, change, delete) - this could be distingueshed as being able to manage other user's drafts not just only own. publish drafts by default all users would have create / save drafts rights and superuser would have all roles. then some could be assigned as managers and/or publishers the other question then is - can the mandatory approval step be made optional. e.g. some users could save drafts or pages, but some limited to only being able to create/manage their own drafts. my 2c 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