vova07 / yii2-imperavi-widget

Imperavi Redactor widget for Yii 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Drag and Drop not inserting to text-area

jonny7 opened this issue · comments

commented

Hi

I'm not sure if I'm doing this right, I did have a look over the usage instructions and tried some examples, but couldn't seem to get it to work. My image uploads fine, but the image never ends up in the text-area. I've tried with "drag and drop" and also clicking the "insert image" button and choosing the file. Could you help me see what I'm missing:

Html::label('Message') . ' ' . \vova07\imperavi\Widget::widget([
                    'name' => 'message',
                    'settings' => [
                        'id' => '#redactor-text',
                        'minHeight' => 400,
                        'imageUpload' => 'upload',
                        'plugins' => [
                            'clips',
                            'fullscreen'
                        ]
                    ]
                ]);

I'm returning as per Imperativ docs in my controller after upload:

$array = [
                'url' => '/images/email/' . $file,
                'name' => $_FILES['file']['name'],
            ];
            
            echo stripslashes(json_encode($array));

If the upload fails I get an error in sorts in that it will alert(true);. But no callback if it succeeds, I tried adding a 'callbacks' => [ 'imageUpload' => new JsExpression("function(){alert('hello');}) ] to the settings key. But this didn't seem to fire?

Thanks 👍

Hi @jonny7 ,
I think the problem is in your custom action you use to upload the images.
Even if it upload the image correctly you didn't return a valid response for image manager to be able to handle that inserted image.

Please try to return a such kind of array instead:

$array = [
    'id' => $_FILES['file']['name'],
    'filelink' => '/images/email/' . $file,
];

As a note:
The callback will fire on successful image upload is called imageUploadCallback and the one will fire on fail upload is imageUploadErrorCallback.

Good luck!

commented

Thanks friend! I was flipping between the Imperavi docs and yours and missed that key! Great wrapper! 🥇