Closed JayDevlin closed 1 month ago
If there is a FileAttachmentField in ModelAdmin the detach method won't work as expected. You will need to click detach & save twice as in "Detach => ID=0 => Save => Image reappears=> Detach => Save => Image detached".
This seems to be only the case in ModelAdmin.
I've traced the problem to FileAttachmentField->setValue(). https://github.com/unclecheese/KickAssets/blob/master/code/FileAttachmentField.php#L35
// if button detach clicked then ID = 0, so this condition fails if($id = Controller::curr()->getRequest()->requestVar($this->Name()."ID")) { $value = $id; } // in ModelAdmin: the old DataObject will overwrite the currently detached file elseif(!$value && $data && $data instanceof DataObject && $data->hasMethod($this->name)) { $funcName = $this->name; if($obj = $data->$funcName()) { if($obj instanceof File) { $value = $obj->ID; } } }
My fix is to check requestVars with isset():
$requests = Controller::curr()->getRequest()->requestVars(); if( isset($requests[$this->Name()."ID"])) { $value = $requests[$this->Name()."ID"]; } elseif(!$value && $data && $data instanceof DataObject && $data->hasMethod($this->name)) { $funcName = $this->name; if($obj = $data->$funcName()) { if($obj instanceof File) { $value = $obj->ID; } } }
If there is a FileAttachmentField in ModelAdmin the detach method won't work as expected. You will need to click detach & save twice as in "Detach => ID=0 => Save => Image reappears=> Detach => Save => Image detached".
This seems to be only the case in ModelAdmin.
I've traced the problem to FileAttachmentField->setValue(). https://github.com/unclecheese/KickAssets/blob/master/code/FileAttachmentField.php#L35
My fix is to check requestVars with isset():