我已经在自己的网站上实施了Quill's WYSIWYG editor。因此,我还需要一个图像缩放器,许多人推荐了this component。我还安装了PHP Quill Renderer来将Quill的Delta转换为HTML。
我测试了所有内容,并且一切正常(我从渲染器接收的数据与我随表格发布的数据相对应。)
但是,如果我在羽毛笔编辑器中调整大小并将其发送到渲染器,则会出现此错误:
Fatal error: Uncaught TypeError: Argument 1 passed to DBlackborough\Quill\Delta\Html\Insert::__construct() must be of the type string, array given, called in ...... on line 22
我检查了文件,此功能在第22行:
public function __construct(string $insert, array $attributes = [])
{
$this->tag = null;
$this->insert = $insert;
$this->attributes = $attributes;
}
作为所有这些的初学者,我不知道该怎么办。我认为是因为我使用的外部组件(即 Quill Image Resizer )不属于 Quill JS ( Php Quill Renderer的开发人员未添加对图像大小调整的支持。
有人可以指导我完成纠正该错误的步骤吗?
答案 0 :(得分:1)
我遇到了同样的问题,这是我的纠正方法
有关该问题的信息:
调整图像大小时,width="xx"
插件会插入Quill Image Resizer
属性。但是在PHP Quill Renderer
中,“解析”不知道此属性,因为没有Delta关联,将使用默认属性。
switch ($attribute) {
default:
$this->insert($quill);
break;
}
解决方案:
要解决此问题,我们需要在选项中添加一个新的width
常量,然后在解析中我们需要添加一个新的case
将此常量链接到图像。
页面:Options.php(ligne:50)
public const ATTRIBUTE_WIDTH = 'width';
public const ATTRIBUTE_ALT = 'alt';
页面:Parser / Parse.php(ligne:179)
case Options::ATTRIBUTE_WIDTH:
$this->image($quill);
break;
case Options::ATTRIBUTE_ALT:
$this->image($quill);
break;
不确定这是最好的解决方案,但它可以解决问题,并且基本功能不会更改。如您在我的代码中看到的,我还添加了alt
属性以将其与图像相关联。这可能对您有利可图
祝你好运!