Attach uploaded files directly to parent if exists

If the parent of the file attachment relationship already exists, then attach the file directly to it in this request instead of going through deferred bindings. Will continue to attach files through deferred binding if the parent relation doesn't exist.
This commit is contained in:
Luke Towers 2018-03-09 23:47:16 -06:00 committed by GitHub
parent f056e8dcb2
commit 422a99770c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -394,7 +394,15 @@ class FileUpload extends FormWidgetBase
$file->is_public = $fileRelation->isPublic();
$file->save();
$fileRelation->add($file, $this->sessionKey);
/**
* Attach directly to the parent model if it exists,
* else attach via deferred binding
*/
if (@$fileRelation->getParent()->exists) {
$fileRelation->add($file);
} else {
$fileRelation->add($file, $this->sessionKey);
}
$file = $this->decorateFileAttributes($file);