Giter Site home page Giter Site logo

syliusadminnotificationplugin's Introduction

Tests

Admin Notification Plugin

Notification messages in your Sylius admin panel.

Features

  • Add custom notification messages in your Sylius admin panel.
  • Show list of notifications

Requirements

Version
PHP ^7.4, ^8.0
Sylius ^1.9

Installation

  1. Add the bundle and dependencies in your composer.json :

    composer require synolia/sylius-admin-notification-plugin
  2. Import routing in your project config/routes/synolia_sylius_admin_notification.yaml:

    synolia_sylius_admin_notification_plugin:
        resource: "@SynoliaSyliusAdminNotificationPlugin/config/routes/admin_routing.yaml"
        prefix: '%sylius_admin.path_name%'
  3. Apply plugin migrations to your database:

    bin/console doctrine:migrations:migrate

How to create a notification

Send notification using Symfony notifier

<?php

declare(strict_types=1);

namespace App\Notification;

use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\NotifierInterface;

final class SendTestNotification
{
    private NotifierInterface $notifier;

    public function __construct(NotifierInterface $notifier) {
        $this->notifier = $notifier;
    }

    protected function send(string $title, string $content): void
    {
        $notification = (new Notification($title, ['chat/admin_notification']))
            ->content($content);

        $this->notifier->send($notification);
    }
}

Send notification using monolog handler

monolog:
    channels: ['synolia_sylius_admin_notification']
    handlers:
        synolia_sylius_admin_notification:
            channels: [synolia_sylius_admin_notification]
            level: debug
            type: service
            id: Synolia\SyliusAdminNotificationPlugin\Handler\Monolog\AdminNotificationHandler
<?php

declare(strict_types=1);

namespace App\EnvieDeFraiseBundle\Command;

use Psr\Log\LoggerInterface;

final class SendTestNotification
{
    private LoggerInterface $synoliaSyliusAdminNotificationLogger;

    public function __construct(LoggerInterface $synoliaSyliusAdminNotificationLogger) {
        $this->synoliaSyliusAdminNotificationLogger = $synoliaSyliusAdminNotificationLogger;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->synoliaSyliusAdminNotificationLogger->critical('Notification message', [
            'context_1' => 'this is the first context',
            'context_2' => [
                'key' => 'val'
            ],
        ]);
    }
}

Write logs as notification

monolog:
    handlers:
        synolia_sylius_admin_notification:
            level: debug
            type: service
            id: Synolia\SyliusAdminNotificationPlugin\Handler\Monolog\AdminNotificationHandler
        main:
            type: fingers_crossed
            action_level: error
            handler: grouped
            channels: [ "!deprecation", "!sonata"]
            excluded_http_codes: [404, 405]
            buffer_size: 50 # How many messages should be saved? Prevent memory leaks
        grouped:
            type: group
            members: [ nested, deduplicated ]
        nested:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        deduplicated:
            type: deduplication
            handler: synolia_sylius_admin_notification

Development

See How to contribute.

License

This library is under the EUPL-1.2 license.

Credits

Developed by Synolia.

syliusadminnotificationplugin's People

Contributors

oallain avatar thegrimmchester avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.