Field type to move an item from a multi-item region to another one in PerchCMS.
- Download zip archive and extract locally.
- Create a
frwssr_moveitem
folder in the/perch/addons/fieldtypes/
folder of your perch install. - Copy the files
frwssr_moveitem.class.php
,index.php
, andinit.js
to the/perch/addons/fieldtypes/frwssr_moveitem
folder.
In a perch template, you can use this field type as simple as follows:
<perch:content id="move" type="frwssr_moveitem" moveto="123|news,456|archive" suppress>
- moveto - Provide the regions, the item may be moved to. Failing to do so will render an alert in Perch Admin. Also give a readable label for each region—separated from its ID with the pipe character (
|
), as you might be familiar with from Perch’sselect
field options. The order has to beID|label
. Pattern:123|news,456|archive
.
Example:moveto="123|news,456|archive"
. - hint - Customize the text on the first—otherwise empty—list item. Defaults to “
↗️ Move item⚠️ ” (—the emoji trying to signify the danger zone character of the field.) - styles - Customize the styles of the field with CSS. Defaults to
background-color: slategray
. You may get fancy with something likestyles="background-color: teal; background-image: linear-gradient(to top right, teal, tomato); border-radius: 10px 0 10px 10px; border: 2px dashed tomato"
, too. Impress your Perch users! - 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, the 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 thehtml
attribute on the outputting field for it to render as desired.
Pattern:id|,id|unset value
.
Example:unsetfields="slug,date,islive|❌"
.
<perch:content id="move" type="frwssr_moveitem" label="Move this awesome item" moveto="123|news,456|archive" hint="Select target region" styles="background-image: linear-gradient(to top right, teal, tomato)" unsetfields="slug,date,islive|❌" help="Beware: The move will be executed ON CHANGE of this field." suppress>
- Make sure, the target regions match the template of the original region—and, that those are multi-item regions, too!
- Always include the original region in the moveto options for better usability/error correction. The original region will be displayed
disabled
in the drop-down list. - The target region may live in another page.
- Always use
suppress
on thefrwssr_moveitem
field to make sure it doesn’t show up in your website (if the same template is used to render the content, that is). - This fieldtype was developed under Perch Runway Version 4.5 on a server running PHP 8.0.x.
Use at own risk!
I want to thank fellow Percher Hussein Al Hammad 🐳 for pointing me in the right direction on troubleshooting PHP Exceptions.
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_moveitem/issues or better yet become a contributor.
Developer: Nils Mielke ([email protected], @nilsmielke on Mastodon) of FEUERWASSER