Extending Files Field

Hi all,
I’m trying to write a plugin that extends a files field to add a cropping interface in the panel (on a page block). The cropping part is working fine, and I’ve tried it a few different ways, but as soon as the page is saved my crop data is lost.

Currently I’m trying to save it all as a json string with the files list as a field and the crop data as a field, like:
{ crop: …, files: […]}
My vue file just calls the k-files-field like so:


and my index.php is just:

Kirby::plugin('wsp/crop', [
    'fields' => [
        'crop' => [
          'extends' => 'files'

If I crop an image it emits the new values fine (as a string), and if I reload the page, the field gets instantiated with the correct values. The images are there and so is the crop data. But as soon as I click “Save” and reload the page, the new value is [ ] (a non-string array)

I’ve also tried adding the crop data directly to the files as an extension of the k-files-field, but that data gets erased too.

I’m assuming there’s some kind of custom saving logic or validation on the php side I can’t find. I’ve tried to look in the kirby repos, but can’t seem to figure it out.

Any help would be greatly appreciated. Thanks!

All fields have a save() method on the PHP side, have a look at the files field:


This might also help: k3-image-clip/image-clip.php at master · mullema/k3-image-clip · GitHub

Thank you! That file looks like what I needed.