Winter/wn-notes-plugin

轻松地为WinterCMS中的任何记录添加备注

资助包维护!
WinterCMS
Open Collective

安装: 948

依赖项: 0

建议者: 0

安全: 0

星标: 12

关注者: 4

分支: 5

开放问题: 1

语言:JavaScript

类型:Winter插件

v1.0.5 2022-01-17 19:57 UTC

This package is auto-updated.

Last update: 2024-09-07 01:43:17 UTC


README

通过类似Mac OS的用户体验,轻松地将备注添加到WinterCMS中的任何记录。

Screenshot of Notes FormWidget

安装

要使用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',
            ]]);
        });
    }
}