reverserelations icon indicating copy to clipboard operation
reverserelations copied to clipboard

Adds user elements support & delete functionality (closes #6)

Open chasegiunta opened this issue 9 years ago • 6 comments
trafficstars

Could be optimized a slight bit more to only save newly added targets now since we know which ones are new, old, and removed, but works great for now. Untested with locales.

chasegiunta avatar Aug 30 '16 21:08 chasegiunta

Thanks! Can you make sure the code is valid PSR-2 and has DocBlocks?

boboldehampsink avatar Aug 31 '16 06:08 boboldehampsink

let me know if that works

chasegiunta avatar Aug 31 '16 16:08 chasegiunta

sigh hold off on merge... Delete functionality works perfectly, as desired, if editing fields or saving from the Control Panel. Unfortunately, saving from the front-end does not.

$this->element->getContent()->getAttribute($this->model->handle) in the FieldType's onAfterElementSave() does not return the field's content upon saving from front-end (or using Import plugin), therefore we're assuming the field is empty and deleting all target relations.

@boboldehampsink if you have any insight on how to fix this, please let me know.

chasegiunta avatar Sep 01 '16 17:09 chasegiunta

Yeah, you should not use getAttribute, just something the lines of $this->element->getContent()->{$this->model->handle} as the getters/setters do some additional magic

boboldehampsink avatar Sep 02 '16 07:09 boboldehampsink

Unfortunately, that only works if the POST content contains the field value. If you save an entry that contains a custom (reverserelations) field, yet don't include the field in your content upon save, it won't see it.

I'm afraid I might have to try Craft's onSaveElement event, unfortunately. Not as simple as I would have hoped.

chasegiunta avatar Sep 02 '16 16:09 chasegiunta

I've worked on this for too long. Unfortunately I'm just not able to wrap my head around what's going wrong. I'm think whatever you're doing in the prepValue function might be the culprit, but it's over my head and I can't seem to find anyone to help me. If you're unable to troubleshoot it, go ahead and close.

chasegiunta avatar Sep 03 '16 19:09 chasegiunta