Field type to clone an item in a multi-item region in PerchCMS.
- Download zip archive and extract locally.
- Create a
frwssr_cloneitemfolder in the/perch/addons/fieldtypes/folder of your perch install. - Copy the files
frwssr_cloneitem.class.php,index.php, andinit.jsto the/perch/addons/fieldtypes/frwssr_cloneitemfolder.
In a perch template, you can use this field type as follows:
<perch:content id="clone" type="frwssr_cloneitem" suppress>- buttontext - Customize the text on the button. Defaults to “✌️ Clone item
⚠️ ” (—the emoji trying to signify the danger zone character of the button.) - buttonbg - Customize the background of the button. Defaults to
slategray. You might get fancy with something likebuttonbg="linear-gradient(to top right, teal, tomato)", too. Impress your Perch users! - renamefield - Pass the ID of a heading field (or similar) to alter said field in the clone.
- renamepostfix - Customize the text appended to the field passed with
renamefield. Will do nothing, ifrenamefieldis not present.
Defaults to “ (Copy)”. - unsetfields - Pass the IDs of one or more fields to be unset—and the (optional) desired unset values—to have them unset/altered. If no value is provided, field will be set to an empty string.
Be aware, that commas (,) and the pipe character (|) cannot be part of an unset value. You may use encoded HTML characters, though need to have thehtmlattribute on the outputting field for it to render as desired.
Pattern:id|,id|unset value.
Example:unsetfields="slug,date,islive|❌".
<perch:content id="clone" type="frwssr_cloneitem" buttontext="Make a copy of this awesome item" buttonbg="linear-gradient(to top right, teal, tomato)" renamefield="itemheading" renamepostfix="—copy" unsetfields="slug,date,islive|❌" suppress>- Use
suppresson thefrwssr_cloneitemfield to make sure it doesn’t show up in your website (if the same template is used to render the content). - The occult
_titlefield of the content item will get the postfix (custom or default) appended, now matter what, to let you know, you are in the newly cloned content item. Even if you do not make use ofrenamefield. Be aware, that if you do not change the value of the field, that is the basis for_title, in the cloned item, the_titlewill change back to its original value, as soon as you save the new content item. - If you are creating a slug (or something similar) of any field in the template, make sure to unset that field using the
unsetfieldsattribute, in order to not end up with duplicate slugs. - This fieldtype was developed under Perch (Standard) Version 3.1.7 on a server running PHP 7.4.x.
Use at own risk!
I want to thank fellow Percher Jordin Brown for pointing me in the right direction and his enlightening feedback.
This project is free, open source, and GPL friendly. You can use it for commercial projects, for open source projects, or for almost whatever you want, really.
This is free software, but it took some time to develop. If you use it, please let me know—I live off of positive feedback…and chocolate. If you appreciate the fieldtype and use it regularly, feel free to buy me some sweets.
Create a GitHub Issue: https://github.com/frwssr/frwssr_cloneitem/issues or better yet become a contributor.
Developer: Nils Mielke (nils.m@feuerwasser.de, @nilsmielke) of FEUERWASSER