mirror of
https://github.com/flarum/core.git
synced 2025-08-17 22:01:44 +02:00
Add Notification extender beforeSending method (#2533)
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
namespace Flarum\Extend;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Foundation\ContainerUtil;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class Notification implements ExtenderInterface
|
||||
@@ -18,6 +20,7 @@ class Notification implements ExtenderInterface
|
||||
private $serializers = [];
|
||||
private $drivers = [];
|
||||
private $typesEnabledByDefault = [];
|
||||
private $beforeSendingCallbacks = [];
|
||||
|
||||
/**
|
||||
* @param string $blueprint The ::class attribute of the blueprint class.
|
||||
@@ -51,6 +54,17 @@ class Notification implements ExtenderInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable|string $callback
|
||||
* @return self
|
||||
*/
|
||||
public function beforeSending($callback)
|
||||
{
|
||||
$this->beforeSendingCallbacks[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extend(Container $container, Extension $extension = null)
|
||||
{
|
||||
$container->extend('flarum.notification.blueprints', function ($existingBlueprints) {
|
||||
@@ -74,5 +88,9 @@ class Notification implements ExtenderInterface
|
||||
$container->extend('flarum.notification.drivers', function ($existingDrivers) {
|
||||
return array_merge($existingDrivers, $this->drivers);
|
||||
});
|
||||
|
||||
foreach ($this->beforeSendingCallbacks as $callback) {
|
||||
NotificationSyncer::beforeSending(ContainerUtil::wrapCallback($callback, $container));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user