lpa Posted February 5 Posted February 5 I have a Page Reference -field in my template. How could I make that field to copy the selected page under the current page and make the reference to point to the cloned page?
virtualgadjo Posted February 6 Posted February 6 hi, that sounds like a good call for a three steps hook on page save ready step one, get the value (id) of the refpage step two $pages->clone(the id) and then get the id of the page newly created setp three yourreferencefield->set() of course, this will be easy with a single page reference field for a multiple pages one, a foreach will be necessary and for step three i must admit that having played a lot with ref field i would probably go for an sql query to update your ref field table (field_fieldname) and set data = new page id where data = former page id hope it may help 🙂 have a nice day
lpa Posted February 6 Author Posted February 6 Sounds good, thanks. But if it is on page save ready -hook, this happens on Page Save? Or is the SaveReady run when you select an old reference? But off course it is quite difficult user experience to make it happen just by selecting a reference from an old page.
virtualgadjo Posted February 6 Posted February 6 hi @lpa actually the save ready event is a "funny" one, it happens when you're saving the page but before the saving if done, this way what you launch is in a way prepared and done juste before the cms really saves the page it's an event i really like as instead of field events that may charge the server each time you change your mind about a field value/content, this one happens when you're done and... ready to save the page and, of cours, you see the result as soon as the page is saved but, of course, we're speaking pw here and you have a lot of events to choose from, have a look at the hookable event of a field https://processwire.com/api/ref/process-field/ the important thing being always to be careful with the cms and server charge 🙂 have a nice day
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