8

I am using Yii2 Redactor from Here. I want to remove Image and File Upload.

view Code :

<?= $form->field($model, 'reason')->widget(
\yii\redactor\widgets\Redactor::className(), [])

 ?>

Screenshot

Screen shot

Ramratan Gupta
  • 1,056
  • 3
  • 17
  • 39
Kakul Sarma
  • 303
  • 1
  • 4
  • 21

2 Answers2

7

If you want to hide the buttons for all instances of Redactor you can add this into the module config

'modules' => [
    'redactor' => [
        'class' => 'yii\redactor\RedactorModule',
        'widgetClientOptions' => [
            'buttonsHide' => ['image','file'],
        ]
    ],
],

Otherwise you can add this to the individual call

<?= $form->field($model, 'reason')->widget(\yii\redactor\widgets\Redactor::className(), [
    'clientOptions' => [
        'buttonsHide' => ['image','file'],
    ]
])?>
Ed209
  • 821
  • 5
  • 8
  • 1
    Note that hiding this buttons does not disable upload functionality - controller will still handle uploads if it will get valid request. It may be security vulnerability (anyone will be able to upload files to your server). – rob006 Jun 01 '18 at 09:43
  • @rob006 Do you have any better sollution ? – Kakul Sarma Jun 07 '18 at 09:12
-2

In this library, you just have to update file i.e. Redactor.php at path yii2-redactor/widgets/Redactor.php

Now update method defaultOptions. Comment or Remove line from 92 to 103 Here is code of these lines:

$this->setOptionsKey('imageUpload', $this->module->imageUploadRoute);
        $this->setOptionsKey('fileUpload', $this->module->fileUploadRoute);
        $this->clientOptions['imageUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'imageUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
        $this->clientOptions['fileUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'fileUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
        if (isset($this->clientOptions['plugins']) && array_search('imagemanager', $this->clientOptions['plugins']) !== false) {
            $this->setOptionsKey('imageManagerJson', $this->module->imageManagerJsonRoute);
        }
        if (isset($this->clientOptions['plugins']) && array_search('filemanager', $this->clientOptions['plugins']) !== false) {
            $this->setOptionsKey('fileManagerJson', $this->module->fileManagerJsonRoute);
        }
Himanshu Batra
  • 98
  • 1
  • 10