I have a two part question.
1: I'm wondering if I can create a new action button next to the save/publish buttons on a page - are there any guides?
2: Is it possible to make an action where a page is moved to a sub-folder in it's current folder?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
I have a two part question.
1: I'm wondering if I can create a new action button next to the save/publish buttons on a page - are there any guides?
2: Is it possible to make an action where a page is moved to a sub-folder in it's current folder?
1. Unfortunately, not easily. So no, not really. (So far as I'm aware)
2. Use drag and drop reordering on the site tree :)
1: Ah, shame.
2: This is my back-up option if it's not possible to automate, in this use case the aim is to move a page to an 'expired' sub-folder on a manual trigger, but the content authors may easily forget to carry this out. An alternative scenario could be for pages to expire after a certain date.
The only way I can think of is with a brute-force write to the SiteTree tables, but I am worried about side-effects from this approach.
Matty,
You could perhaps consider making use of just the framework to make a custom class that is then invoked by a Crontab on a frequent basis? - Just a thought.
Why is a page expiring, out of interest? - Perhaps you might be better of with a ModalAdmin for content of that type?
Matty, it sounds like you're after something similar to what the advanced workflow module would provide. Perhaps you should look into the available addons (I'm sure there are a couple at least that deal with embargo/expiry).
Thanks for the tips. More details as requested: This is a new feature for a non-e-commerce site displaying second-hand goods where all products are individual pages:
At the moment all items are shown in a holder page for each make.
They now want to:
1: Show all items currently for sale.
2:As soon as they are sold they need to move to a different location, and be listed according to the date they were sold.
This could of course all be accomplished by a content author setting a date and then moving the item, but the request is to automate the whole process down to one-click operation when sold - if at all possible.
Hmm, personally I would have made the goods a dataobject and related them to a holder rathern than children pages.
But if they're pages and you're stuck with that, then allowed_children on the holder to ensure all children are goods pages, then find some (sane) way to limit the goods pages to be directly under a holder.
That way you can define a place to move the children to on expiry on the holder, and have the children obtain this information through their $this->Parent() relation.
This way you could have separate archives per type of goods being sold (if they're catagorised) or otherwise perhaps define a site wide setting on SiteConfig (a universal archive) and have the goods pages obtain this via their $this->SiteConfig() relation.
As for automatic movement, you'd have to set and expiry field on the goods pages (no surprise), and either have that checked in canView (or similar) before loading (perhaps in init() ) and deny&move when applicable, or set up a cron job as George has suggested already, with a task that runs at midnight.
Thanks for everyone's input. Data Objects would have indeed make this easier - but rewriting outside of the budget in this case.
In the end I managed to run some tests on 'onBeforeWrite' to accomplish the moving when sold.
1: I added a new date field which is written to on save/publish when a 'sold out' checkbox is ticked.
2: I created a new type of holder page for sold items: if this exists, the ParentID on the sold product is then overwritten, moving it in the Sitetree.
It seems to work really well as far as I can tell.