Collection events on the admin side for edit/udpate view pages

Hey guys I’m wondering if anyone can suggest a workaround for my issue.

I have created a new Addon for fieldtype called “Encrypt” so its just a plain text field that will encrypt value when saving to database and decrypt when retrieving.

I can get the decrypted value while previewing list of entries in the admin and via rest api. However, I cannot seem to figure out how to decrypt it while in the update/edit page of the entry. I get the ecrypted value in the input area.

Right now I’m hardcoing an event within modules/Collections/Controller/Admin.php around line 175 with this $this->app->trigger("collections.admin.entry", [&$entry]);. This way I can catch the entry before showing and decrypt the values for my fieldtypes.

I guess my question is anyone know if there is a way to hook into the entry to update values before its rendered to the view? Is there something I can do within the .tag file for my field-encrypt.tag?

Let me know if this makes sense? Thanks!!!

Hey @owldesign, yes, I think you need to do it inside your field-encrypt.tag, maybe something like:

this.$updateValue = function(value, field) {
  this.value = your_decrypt_function(value);
  this.update();
}.bind(this);

@pauloamgomes how would I make a call to php method within that? Would I have to make a GET/POST request?

Edit: Ok I figured it out now. I created a Controller class with methods. And from my tag file I do a $.get reqeuest to my controller method to decrypt the value.

I’ll post the encryption field addon once I test/clean it up. Thanks for the help!

Edit 2: I published my addon on github. Maybe someone can give it a test drive https://github.com/owldesign/Encrypt its my first addon and just few days digging around Cockpit so I’d appreciate any feedback on what I’m doing wrong. Thanks!!

1 Like

Nice work @owldesign, will look in more detail, but probably you should put the vendor folder in .gitignore