Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-09-09 20:49:11

albatros69
Member
Registered: 2021-06-17
Posts: 21

Clear a custom field on duplicate

Dear all,

I need to clear a specific custom field when a user clones an article. I managed to do it in the Write panel using JS (by emptying the input field on click). However, I can’t find a solution in case the user duplicates articles in multi-edit. I was first confident to succeed adding a callback on multi_edited.articles>duplicate. But the callback gets as parameters the selected articles and no the newly created ones, so it’s impossible to perform actions on these one. Second option would be to act on articles>multi_edit.duplicate, but again, I can only act on the original articles and they must remain as is.

Do you imagine another solution, or an hint to find one?
Thanks in advance,

Offline

#2 2021-09-09 21:18:20

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Clear a custom field on duplicate

Hi,

We definitely should add new IDs to callbacks data. Meanwhile, I can not see a better solution than

  • register a callback on 'articles', 'multi_edit.duplicate', 1 that will store the cf values of the articles being duplicated in a ID => value array and then empty them;
  • register a callback on 'multi_edited.articles', 'duplicate', 0 that will restore the cf of the duplicated articles.

Offline

#3 2021-09-09 22:00:34

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Clear a custom field on duplicate

In 4.8.8, $selected array is exported as newid => oldid on duplication now. Please test and comment while it is not yet released.

Offline

#4 2021-09-10 08:45:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Clear a custom field on duplicate

etc wrote #331548:

We definitely should add new IDs to callbacks data.

Agree. I’m still working on completely overhauling the callback names and structure so everything we possibly can has pre- and post-action at minimum, and the payloads will be stuffed with as much data as is available.

Seamlessly mapping the old callbacks to the new is the fun part. I’ve got a local branch set up somewhere for testing this all out, and it was working reasonably well with the small subset of callbacks I revamped. Whether it scales to all callbacks I’m not sure yet.

Might make it public at some point so people can weigh in.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2021-09-10 12:45:14

albatros69
Member
Registered: 2021-06-17
Posts: 21

Re: Clear a custom field on duplicate

etc wrote #331549:

In 4.8.8, $selected array is exported as newid => oldid on duplication now. Please test and comment while it is not yet released.

I will do this probably beg of next week and revert back here.
Thanks a lot for the swift reply.!

Offline

#6 2021-09-15 21:03:43

albatros69
Member
Registered: 2021-06-17
Posts: 21

Re: Clear a custom field on duplicate

albatros69 wrote #331554:

I will do this probably beg of next week and revert back here.
Thanks a lot for the swift reply.!

Seems to work like a charm on my DEV instance. Thanks a lot!
Do you have any date when 4.8.8. will be released?

Offline

#7 2021-09-16 07:14:13

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Clear a custom field on duplicate

albatros69 wrote #331618:

Seems to work like a charm on my DEV instance. Thanks a lot!
Do you have any date when 4.8.8. will be released?

Thanks for testing. Txp 4.8.8 is meant to be php 8.1 compatible, so will probably be released at the same moment (end of November). But you could try to grab the current txp_list.php and use it in 4.8.7, they should be compatible.

Offline

Board footer

Powered by FluxBB