furbo / museum-plus-for-craft-cms
允许导入MuseumsPlus收藏数据到Craft CMS并发布数据。
Requires
- php: >=8.0.2
- craftcms/cms: ^4.3.4
- gemini-api-php/client: ^1.4
This package is auto-updated.
Last update: 2024-09-21 21:34:51 UTC
README
允许导入MuseumsPlus收藏数据到Craft CMS并发布数据。
要求
此插件需要Craft CMS 4.7或更高版本以及php 8.1或更高版本。
安装
要安装此插件,请按照以下说明操作。
-
打开您的终端并转到您的Craft项目
cd /path/to/project
-
然后告诉Composer加载插件
composer require furbo/museum-plus-for-craft-cms
-
在控制面板中,转到设置→插件,然后点击MuseumPlus for CraftCMS的“安装”按钮。
概述
MuseumPlus for CraftCMS自动从一个或多个收藏中导入项目,并使它们在Craft中可用。
功能
- 从Craft导入M+数据
- 将图片或其他文件导入Craft文件系统
- 使用Craft转换生成缩略图等
- 向项目添加附加字段
- 显示项目详细信息或筛选列表(按词汇、人物筛选等)
- 在Craft全文搜索中包含项目
- 自动从AI(Google Gemini)丰富数据。
配置
一旦安装了插件,您就可以在Craft控制面板的设置→MuseumPlus for CraftCMS下进行配置。您需要提供以下内容:
- 博物馆Plus分类器
- MuseumPlus API的主机名
- MuseumPlus API用户名
- MuseumPlus API密码
保存设置后,您将看到您有权访问的收藏列表:至少选择一个收藏并保存设置。您还应该选择存储媒体文件的文件系统:请注意,将在文件系统的根目录中自动创建两个子文件夹Items
和Multimedia
。您可以指定要导入的文件类型:插件将下载文件并将它们存储在选择的文件系统中。在设置中有一个部分可以定义用于在前端显示收藏项的URI格式和模板。
shell命令./craft museum-plus-for-craft-cms/collection/update-items
将导入所选收藏的数据。我们建议设置cron作业定期运行此命令。
使用方法
在后台,您将看到一个名为“收藏”的新部分,其中您可以查看导入的收藏及其项目
显示项目的前端示例
{% set items = craft.museumPlus.items.all() %}
{% for item in items %}
<h2>{{ item.title }}</h2>
<p>{{ item.description }}</p>
<img src="{{ item.image.getUrl() }}" alt="{{ item.title }}">
{% endfor %}
按词汇引用筛选项目列表的前端示例
{% set vocabulary = craft.museumPlus.getVocabularyById(id) %}
{% set items = vocabulary.getItems() %}
{% for item in items %}
<h2>{{ item.title }}</h2>
<p>{{ item.description }}</p>
<img src="{{ item.image.getUrl() }}" alt="{{ item.title }}">
{% endfor %}
显示单个项目的前端示例
{% set item = craft.museumPlus.getItemById(id) %}
{% set attachment = item.getAttachment() %}
{% if attachment %}
{% set myAssetUrl = attachment.getUrl() %}
<img src="{{ attachment.getUrl("transformL") }}" alt="{{ attachment.title }}" />
{% endif %}
<h2>{{ item.title }}</h2>
在twig中可用的其他方法
craft.museumPlus.getItemById(id)
craft.museumPlus.getItemsByIds(ids)
craft.museumPlus.getVocabularies($type)
craft.museumPlus.getVocabularyById(id)
craft.museumPlus.getAllPeople()
craft.museumPlus.getPeopleById(id)
craft.museumPlus.getObjectGroupById(id)
craft.museumPlus.getAllObjectGroups()
craft.museumPlus.searchItems(params)
项目上可用的方法
- getAttachment // gets the main image / file
- getMultimedia // gets other images / files
- getObjectGroups // dito
- getLiterature // dito
- getOwnerships // dito
- getAssociationPeople // dito
- getOwnerPeople // dito
- getAdministrationPeople // dito
- getRelatedItems // gets the items related to this object
- getVocabularyEntries // gets the vocabulary entries related to this item
- getVocabularyEntriesByType(type) // gets the vocabulary entries related to this item filtered by type
词汇条目上可用的方法
- getItems() // gets all ietms associted by this type
- getParent() // get the parent vocabulary node
- getParents() // get all parents up the tree
- getPath() // get all parents up the tree plu sthe node itself
getRecords方法提供了对底层记录元素的访问权限。以下是可以在记录(项目、人物、对象组、词汇条目、文献、所有权)上调用的方法
- getRepeatableGroupValues(groupName, attribute = null, filterTypes = [])
- getDataAttributes() (for all)
- getDataAttribute(name)
从人物、对象组、词汇条目、文献、所有权等对象获取项目
- rec.getItems()
事件
插件在项目被插件更新或创建后抛出一个自定义事件。自定义模块可以监听此事件并添加一些自定义功能。
将此代码添加到craft cms中自定义模块的init()方法。
Event::on(
MuseumPlusForCraftCms::class,
MuseumPlusForCraftCms::EVENT_ITEM_UPDATED_FROM_MUSEUM_PLUS,
function(ItemUpdatedFromMuseumPlusEvent $e) {
//Example: lets say you have an extra field, for example is_new to show alle the newly created items in a collection.
//The field can the be removed manually from the backend
$item = $e->item;
if ($e->isNewItem) {
$item->is_new = true;
Craft::$app->elements->saveElement($item);
}
}
);
路线图
- 向项目添加通过Google添加的地理引用
由Furbo GmbH提供