Winter / wn-notes-plugin
轻松地为WinterCMS中的任何记录添加备注
v1.0.5
2022-01-17 19:57 UTC
Requires
- composer/installers: ~1.11
README
通过类似Mac OS的用户体验,轻松地将备注添加到WinterCMS中的任何记录。
安装
要使用Composer安装,请在项目根目录中运行composer require winter/wn-notes-plugin
。
要从仓库安装,将其克隆到plugins/winter/notes
,然后从项目根目录运行composer update
以引入依赖项。
文档
只需将notes
MorphMany关系添加到模型,并将类型为notes
的字段添加到fields.yaml中即可开始。
示例 fields.yaml
fields: name: label: Name span: full tabs: fields: notes: # The name of the relationship the FormWidget will use label: '' tab: Notes type: notes span: full # autosaveDelay: 2000 # The amount of milliseconds to delay after typing stops to trigger an autosave # dateFormat: 'Y-m-d H:i:s' # the php date format for updated_at column
示例 MorphMany 关系定义
public $morphMany = [ 'notes' => [\Winter\Notes\Models\Note::class, 'name' => 'target'] ];
将备注字段添加到第三方插件
在您的自定义Plugin.php
插件类中,执行以下操作
<?php namespace MyAuthor\MyPlugin; use Event; use System\Classes\PluginBase; use Winter\Blog\Models\Post; class Plugin extends PluginBase { public function boot() { // Extend the Winter.Blog Post model to add the `notes` relationship Post::extend(function ($model) { $model->morphMany = array_merge($model->morphMany, ['notes' => [\Winter\Notes\Models\Note::class, 'name' => 'target']]); }); // Extend the backend fields to add the notes field Event::listen('backend.form.extendFieldsBefore', function ($widget) { // Only extend forms for the Post model if (!($widget->model instanceof Post)) { return; } // Add the notes field to the form $widget->fields = array_merge($widget->fields, ['notes' => [ 'label' => '', 'tab' => 'Notes', 'type' => 'Notes', 'span' => 'full', ]]); }); } }