confluxgroup / craft-relationshipeditor
允许从前端修改元素关系,而无需重新提交所有选择。
1.0.3
2020-05-08 20:25 UTC
Requires
- craftcms/cms: ^3.0.0
This package is auto-updated.
Last update: 2024-09-09 05:07:32 UTC
README
允许从前端修改元素关系,而无需重新提交所有选择。
关系编辑器与条目、用户、类别和资产协同工作。
要求
此插件需要 Craft CMS 3.0.0 或更高版本。
安装
要安装关系编辑器,请按照以下说明操作。
-
打开您的终端并转到您的 Craft 项目
cd /path/to/project
-
然后告诉 Composer 加载插件
composer require confluxgroup/craft-relationshipeditor
-
通过 CLI 使用
./craft install/plugin relationshipeditor
安装插件,或在控制面板中,转到设置→插件,然后点击关系编辑器的“安装”按钮。
您还可以通过 Craft 控制面板中的 插件商店 安装关系编辑器。
关系编辑器概述
Craft CMS 具有强大的功能,可以通过前端模板创建和编辑条目。然而,编辑条目、用户、类别和资产等元素关系字段可能很棘手,因为它们只会保存请求中提交的相关元素,因此您的前端模板需要重新提交所有先前选择的元素,这使得前端模板更加复杂。
关系编辑器提供了一个专门用于在不重新提交所有现有选择的情况下添加和删除元素关系的操作。
您可以使用关系编辑器允许用户在前端模板中快速轻松地创建心愿单或其他元素集合。该插件遵守 Craft 原生前端表单相同的编辑权限。
使用关系编辑器
使用关系编辑器很简单。只需在您的 Twig 模板中构建一个简单的表单。
需要 elementId
和 fieldHandle
字段,以及 addIds
或 removeIds
,可以是单个元素 ID 的单个字段,或多个 ID 的数组。
<form method="post" accept-charset="UTF-8"> {{ csrfInput() }} <input type="hidden" name="action" value="relationshipeditor/save"> {{ redirectInput('path/to/redirect') }} {# the element containing the relationship you want to edit #} <input type="hidden" name="elementId" value="{{ yourElement.id }}"> {# the handle of the relationship field you want to edit #} <input type="hidden" name="fieldHandle" value="relationshipFieldName"> {# use an addIds field to indicate the element that should be added to the relationship #} <input type="hidden" name="addIds" value="123"> {# use an addIds field as an array to indicate multiple elements that should be added to the relationship #} <input type="hidden" name="addIds[]" value="123"> <input type="hidden" name="addIds[]" value="456"> {# use an removeIds field to indicate the element that should be removed from the relationship #} <input type="hidden" name="removeIds" value="123"> {# use an removeIds field as an array to indicate multiple elements that should be removed from the relationship #} <input type="hidden" name="removeIds[]" value="123"> <input type="hidden" name="removeIds[]" value="456"> <button type="submit">Submit</button> </form>
由 Conflux Group, Inc. 提供