php - 关于:Quill js、Quill-Image-Resize 和 PHP-Quill-Renderer 的问题
问题描述
我已经在我的网站上实现了Quill 的 WYSIWYG 编辑器。有了这个,我还想要一个图像缩放器,很多人推荐这个组件。我还安装了PHP Quill Renderer将 Quill 的 Delta 转换为 HTML。
我测试了一切,它工作正常(我从渲染器收到的数据对应于我在表单中发布的数据)。
但是,如果我在 Quill 编辑器中调整图像大小并将其发送到渲染器,则会收到以下错误:
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 js的一部分的外部组件(即Quill Image Resizer ),所以Php Quill Renderer的开发人员没有添加对图像大小调整的支持。
任何人都可以指导我完成纠正此错误应采取的步骤吗?
解决方案
我有同样的问题,这是我纠正它的方法
有关问题的信息:
当您调整图像大小时,该属性width="xx"
由插件插入。Quill Image Resizer
但是在 中PHP Quill Renderer
,Parse 不知道这个属性,因为没有 Delta 关联使用默认值。
switch ($attribute) {
default:
$this->insert($quill);
break;
}
解决方案:
为了纠正这个问题,我们需要width
在选项中添加一个新常量,然后在解析中我们需要添加一个新case
常量来将该常量链接到图像。
页面:Options.php(线: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
属性以将其与图像相关联。它可能对你有利可图
祝你好运 !
推荐阅读
- css - 了解响应式表单 (React) 和冗余的 Flexbox 层次结构?
- amazon-web-services - 启用“自动配置 CloudWatch 日志”时的 AWS 任务定义警告
- python - 用另一个可迭代对象有效地分割可迭代对象
- r - 使用 R 进行 2D 三次插值
- javascript - for 循环中的 addEventListener 仅适用于最后一个元素
- php - 尝试在刀片中获取非对象属性时出错
- html - 内联 Vimeo 按钮覆盖
- vba - 当数据为数千时,我的对帐 VBA 宏运行时间过长
- python - Pandas 填充列中的某些值
- ios - UITableView + UICollectionView + UITableView 大小问题