parent
5ec5336a79
commit
0086a47b80
|
|
@ -71,6 +71,11 @@ class FileUpload extends FormWidgetBase
|
|||
*/
|
||||
public $useCaption = true;
|
||||
|
||||
/**
|
||||
* @var boolean Automatically attaches the uploaded file on upload if the parent record exists instead of using deferred binding to attach on save of the parent record. Defaults to false.
|
||||
*/
|
||||
public $attachOnUpload = false;
|
||||
|
||||
//
|
||||
// Object properties
|
||||
//
|
||||
|
|
@ -92,7 +97,8 @@ class FileUpload extends FormWidgetBase
|
|||
'fileTypes',
|
||||
'mimeTypes',
|
||||
'thumbOptions',
|
||||
'useCaption'
|
||||
'useCaption',
|
||||
'attachOnUpload',
|
||||
]);
|
||||
|
||||
if ($this->formField->disabled) {
|
||||
|
|
@ -395,10 +401,11 @@ class FileUpload extends FormWidgetBase
|
|||
$file->save();
|
||||
|
||||
/**
|
||||
* Attach directly to the parent model if it exists,
|
||||
* Attach directly to the parent model if it exists and attachOnUpload has been set to true
|
||||
* else attach via deferred binding
|
||||
*/
|
||||
if (@$fileRelation->getParent()->exists) {
|
||||
$parent = $fileRelation->getParent();
|
||||
if ($this->attachOnUpload && $parent && $parent->exists) {
|
||||
$fileRelation->add($file);
|
||||
} else {
|
||||
$fileRelation->add($file, $this->sessionKey);
|
||||
|
|
|
|||
Loading…
Reference in New Issue