Provides Comments in Backend
  • PHP 47.2%
  • JavaScript 33.1%
  • HTML 16.3%
  • CSS 3.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-11-26 16:11:01 +01:00
behaviors allows to mass comment related records in form controlelr 2023-02-22 12:59:57 +01:00
classes allows to hook into mentions using events 2022-03-09 14:48:37 +01:00
controllers adds permission to delete comments 2024-03-20 10:54:15 +01:00
formwidgets reduces padding of mention select popover 2024-11-26 16:11:01 +01:00
lang WIP: displays username selection when typing "@" 2024-11-15 18:09:30 +01:00
models adds whitespace after inserted mention + prefixes mention with @ 2024-11-19 08:50:03 +01:00
traits auto deletes comments if parent model is deleted 2023-02-22 14:03:22 +01:00
updates adds comment reactions 2024-04-09 14:35:51 +02:00
composer.json adds docs to README an makes it a winter-plugin 2022-03-09 15:09:33 +01:00
Plugin.php adds permission to delete comments 2024-03-20 10:54:15 +01:00
README.md fixes typo in readme 2022-12-01 14:32:36 +01:00

WinterCMS Backend Comments Plugin

Provides commenting in the backend.

Usage

This plugin provides the StudioBosco\BackendComments\Traits\Commentable Trait and a comments field widget.

To make a model commentable

  1. just add the trait:
class MyModel
{
    use StudioBosco\BackendComments\Traits\Commentable;
    ...

You can set the name of the comments relation in your model if you want anything different then comments:


    /**
     * @var string Name of backend comments relation.
     */
    public $backendCommentsRelation = 'myComments';
  1. Add the comments field to it's model form:
fields:
    _comments:
        type: backendcomments
        dateFormat: d-m-Y H:i:s # use your custom dateformat if required (it also accepts translation strings)
        context: # use update and preview context only as comments do not work deffered
            - update
            - preview

The "comments" field must not have the same name as the relation. By default the relation is called "comments". So use "_comments" for the field name or anything else.

Mentions

If you have the StudioBosco.BackendNotifications plugin installed backend comments allow mentions by writing @username or @first_name or @last_name or @first_and_last_name.

This will trigger an event for every mention before it is turned into a notification.

You can listen to the following event:

studiobosco.backendcomments.mention

Event arguments

  • StudiBosco\BackendComments\Classes\CommentMention - $mention The mention before it triggers a notification. You can mutate this object to e.g. adjusts the notification URL.

An example on how to change the URL of the notification:


Event::listen('studiobosco.backendcomments.mention', function ($mention) {
    $commentable = $mention->comment->commentable;

    if ($commentable) {
        if ($commentable instanceof MyModel) {
            $mention->url = Backend::url('myplugin/mymodel/update/' . $commentable->id);
        }
    }
});