youwe / pimcore-href-typeahead
允许在 href 中使用自动完成功能
v10.0.0
2024-01-09 14:39 UTC
Requires
- pimcore/pimcore: ^10.5
This package is auto-updated.
Last update: 2024-09-09 16:17:09 UTC
README
使用修改后的默认搜索功能,向 href 字段添加自动完成功能
我在字段配置器中将文档和资产设为只读字段,以防止用户在 static/js/pimcore/object/classes/data/hrefTypeahead.js 中选择资产作为有效链接,但我不想删除它,因为我们可能会添加支持资产和文档的功能。我还添加了验证,以防止用户选择多个类
安装
composer require youwe/pimcore-href-typeahead
使用方法
HrefTypeahead 字段将在您的模型类中可用,它与 href 类似,但具有自动完成功能。
配置
当在模型中使用 HrefAutocomplete 时,您可以通过勾选复选框使用 "show_trigger" 选项。这将显示一个小下拉图标,您可以点击它而不是在框中键入。
文件
- static/js/pimcore/object/classes/data/hrefTypeahead.js
- 默认 href 的完整副本
- static/js/pimcore/object/tags/hrefTypeahead.js
- 默认 href 的完整副本,但更改之处在于文本框现在是一个组合框,由 SearchController::findAction 提供自动完成功能
- models/Pimcore/Model/Object/ClassDefinition/Data/HrefTypeahead.php
- 默认 href 的完整副本
- HrefTypeahead/controllers/SearchController.php
- 包含自动完成来源的控制器
事件
当您想在 href 自动完成执行的搜索中添加一些额外的过滤器时,可以使用监听器。示例:
监听器配置(例如,在 src/AppBundle/Resources/config/services.yml 中)
AppBundle\EventListener\HreftypeaheadSearchListener:
tags:
- { name: kernel.event_listener, event: hreftypeahead.search, method: onSearch }
监听器代码(例如,在 AppBundle/EventListener/HreftypeaheadSearchListener 中)
class HreftypeaheadSearchListener
{
/* @var HreftypeaheadSearchEvent */
protected $e;
public function __construct()
{
}
public function onSearch(HreftypeaheadSearchEvent $e)
{
$this->e = $e;
$e->addCondition('(0 = 0)'); // just an example
}
......
限制
- 它只支持在 href 中链接一个对象