Coder Social home page Coder Social logo

creative-commoners / comment-notifications Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silverstripe/comment-notifications

0.0 2.0 0.0 60 KB

Provides simple comment notifications

License: BSD 3-Clause "New" or "Revised" License

PHP 89.44% Scheme 10.56%

comment-notifications's Introduction

Comment Notifications

Build Status Scrutinizer Code Quality codecov.io SilverStripe supported module

Provides simple email notifications for when new visitor comments are posted.

Installation

Install using Composer:

composer require silverstripe/comment-notifications ^2.0

Note: This branch is SilverStripe 4 compatible. For a SilverStripe 3 version please see the 1.x release line.

Configuration

To configure the default email address to receive notifications, place this in your mysite/_config.yml

SilverStripe\Control\Email\Email:
  admin_email: '[email protected]'

Check out the CommentNotifiable class for the list of options you can override in your project.

Configuring Recipients

To define who receives the comment notification define a updateNotificationRecipients method and modify the list of email addresses.

mysite/code/CommentNotificationExtension.php

<?php

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Security\Group;

class CommentNotificationExtension extends DataExtension
{
    /**
     * @param array $existing
     * @param Comment $comment
     */
    public function updateNotificationRecipients(&$existing, $comment)
    {
        // send notification of the comment to all administrators in the CMS
        $admin = Group::get()->filter('Code', 'admin');

        foreach ($admin as $group) {
            foreach ($group->Members() as $member) {
                $existing[] = $member->Email;
            }
        }

        // or, notify the user who originally created the page
        $page = $comment->Parent();
        if ($page instanceof SiteTree) {
            /** @var ArrayList $pageVersion */
            $pageVersion = $page->allVersions('', '', 1); // get the original version
            if ($pageVersion && $pageVersion->count()) {
                $existing[] = $pageVersion->first()->Author()->Email;
            }
        }
    }
}

Apply the CommentNotificationExtension to any classes which have commenting enabled (e.g SiteTree)

mysite/_config/extensions.yml

SilverStripe\CMS\Model\SiteTree:
  extensions:
    - CommentNotificationExtension

comment-notifications's People

Contributors

robbieaverill avatar wilr avatar dhensby avatar assertchris avatar nightjar avatar raissanorth avatar scott1702 avatar emteknetnz avatar dnsl48 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.