reverserelations
reverserelations copied to clipboard
Adds user elements support & delete functionality (closes #6)
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.
Thanks! Can you make sure the code is valid PSR-2 and has DocBlocks?
let me know if that works
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.
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
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.
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.