yii2-froala-editor icon indicating copy to clipboard operation
yii2-froala-editor copied to clipboard

FroalaEditorAsset throws yii\base\Exception

Open floor12 opened this issue 5 years ago • 0 comments

Hi! When i try to use this widget i get the yii\base\Exception with this message: plugin 'align' is not supported, if you trying to set custom plugin, please set 'js' and 'css' options for your plugin. When i read a source code i found next two fragments of code:

$this->registerPlugins(array_diff($this->froalaPlugins, $excludedPlugins ?: []), false, true);

and

 public function registerPlugin($pluginName, $checkJs = true, $checkCss = true)
    {
        $jsFile = "js/plugins/$pluginName.min.js";
        if ($checkJs && $this->isPluginJsFileExist($pluginName)) {
            $this->addJs($jsFile);
            $cssFile = "css/plugins/$pluginName.min.css";
            if (!$checkCss || $this->isPluginCssFileExist($pluginName)) {
                $this->addCss($cssFile);
            }
        } else {
            $thirdPartyJsFile = "js/third_party/$pluginName.min.js";
            if($checkJs && $this->isThirdPartyPluginJsFileExist($pluginName)) {
                $this->addJs($thirdPartyJsFile);
                $thirdPartyCssFile = "css/third_party/$pluginName.min.css";
                if (!$checkCss || $this->isThirdPartyPluginCssFileExist($pluginName)) {
                    $this->addCss($thirdPartyCssFile);
                }
            }
            else {
                throw new Exception("plugin '$pluginName' is not supported, if you trying to set custom plugin, please set 'js' and 'css' options for your plugin");
            }
            
        }
    }

In method registerPlugin, when we call it with $checkJs = false we will always throw an exception. I think, we can change the registerPlugins call to use $checkJs = true:

$this->registerPlugins(array_diff($this->froalaPlugins, $excludedPlugins ?: []), true, true);

After this changing plugins starts ti work. I can make a pull request.

floor12 avatar Oct 10 '19 12:10 floor12