PHP code example of winter / wn-notes-plugin

1. Go to this page and download the library: Download winter/wn-notes-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

winter / wn-notes-plugin example snippets


public $morphMany = [
    'notes' => [\Winter\Notes\Models\Note::class, 'name' => 'target']
];

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