Skip to content

Latest commit

 

History

History
81 lines (63 loc) · 4.28 KB

custom-notification-channel.md

File metadata and controls

81 lines (63 loc) · 4.28 KB

8lines

SyliusNotificationPlugin


Custom Notification Channel

To create a custom Notification Channel, you need to create a class that implements NotificationChannelInterface.

<?php

declare(strict_types=1);

namespace ...;

use EightLines\SyliusNotificationPlugin\NotificationChannel\NotificationBody;
use EightLines\SyliusNotificationPlugin\NotificationChannel\NotificationChannelInterface;
use EightLines\SyliusNotificationPlugin\NotificationChannel\NotificationContext;
use EightLines\SyliusNotificationPlugin\NotificationChannel\NotificationRecipient;

final class CustomNotificationChannel implements NotificationChannelInterface
{

    public function send(
        ?NotificationRecipient $recipient, 
        NotificationBody $body, 
        NotificationContext $context,
    ): void {
        // TODO: Implement send() method.
    }

    public static function getIdentifier(): string
    {
        // TODO: Implement getIdentifier() method.
    }

    public static function supportsUnknownRecipient(): bool
    {
        // TODO: Implement supportsUnknownRecipient() method.
    }

    public static function getConfigurationFormType(): ?string
    {
        // TODO: Implement getConfigurationFormType() method.
    }
}

send()

This method is used to send the notification. It takes three arguments:

  • $recipient - The recipient of the notification. It can be null if the recipient is unknown.
  • $body - The body of the notification. It contains the subject and the message of the notification.
  • $context - The context of the notification. It contains all the information about the notification.

getIdentifier()

This method is used to get the identifier of the Notification Channel.

supportsUnknownRecipient()

This method is used to check if the Notification Channel supports unknown recipients.

getConfigurationFormType()

This method is used to get the configuration form type of the Notification Channel. There are several predefined configuration form types:

Of course, you can create your own configuration form type.

Registering the custom Notification Channel

Service that holds the custom Notification Channel needs to be registered in the service container. It also needs to be tagged with eightlines_sylius_notification_plugin.notification_channel tag. By default, if autoconfiguration is enabled, the service will be automatically tagged with the eightlines_sylius_notification_plugin.notification_channel tag. If not, you need to add the tag manually.