如何禁用或删除 Yii2 编辑器图像和文件按钮?

How to disable or remove Yii2 redactor Image and file button?

我正在使用来自 HereYii2 编辑器。我想删除 Image and File Upload.

查看代码:

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

 ?>

截图

在此库中,您只需更新文件,即 Redactor.php 在路径 yii2-redactor/widgets/Redactor.php

现在更新方法 defaultOptions注释或删除第 92 到 103 行 这是这些行的代码:

$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);
        }

如果您想隐藏所有 Redactor 实例的按钮,您可以将其添加到模块配置中

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

否则您可以将其添加到个人调用中

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