Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Moving pages in Site Tree by action.


Go to End


8 Posts   1178 Views

Avatar
Matty Balaam

Community Member, 74 Posts

11 May 2015 at 9:32pm

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?

Avatar
Pyromanik

Community Member, 419 Posts

11 May 2015 at 11:01pm

1. Unfortunately, not easily. So no, not really. (So far as I'm aware)
2. Use drag and drop reordering on the site tree :)

Avatar
Matty Balaam

Community Member, 74 Posts

12 May 2015 at 2:38am

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.

Avatar
George Botley

Community Member, 18 Posts

12 May 2015 at 8:36pm

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?

Avatar
Pyromanik

Community Member, 419 Posts

12 May 2015 at 8:59pm

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

Avatar
Matty Balaam

Community Member, 74 Posts

13 May 2015 at 2:58am

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.

Avatar
Pyromanik

Community Member, 419 Posts

13 May 2015 at 4:13am

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.

Avatar
Matty Balaam

Community Member, 74 Posts

19 May 2015 at 3:09am

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.