I want to except some notifications from the Telegram flow (or general flow) and I need to define a new NotificationSubscriber but how it should view in the Plugin.php (like helper->register, template->setTemplateOverride etc.)? Are there other ways?
Do you mean $this->dispatcher->addSubscriber
or https://docs.kanboard.org/en/latest/plugins/notifications.html ?
Yes, I think I need $this->dispatcher->addSubscriber, but what the syntax for register a new Subscriber and how to use it?
I’ve used it only in a “private” Plugin, but I could share some code snippets.
Plugin.php
...
use Kanboard\Plugin\AzureDevOps\Subscriber\AzureSubscriber;
...
$subscriber = new AzureSubscriber($this->container);
$this->dispatcher->addSubscriber($subscriber);
AzureSubscriber.php:
<?php
namespace Kanboard\Plugin\AzureDevOps\Subscriber;
use Kanboard\Event\GenericEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Subscriber\BaseSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AzureSubscriber extends BaseSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
TaskModel::EVENT_CREATE => 'handleEvent',
);
}
public function handleEvent(GenericEvent $event, $eventName)
{
$task = $event['task'];
...
}
}
Thank you very much for a reference! But I have HTTP ERROR 500 when trying to enable my Subscriber in Plugin.php, I have the same syntax but probably something wrong. Could you watch it and let me know? Just I need to replace the main NotificationSubscriber.php to my
Plugin.php
…
use Kanboard\Plugin\MyTheme\Subscriber\MyNotificationSubscriber;
…
$this->dispatcher->addSubscriber(new MyNotificationSubscriber($this->$container));
MyNotificationSubscriber.php
<?php
namespace Kanboard\Subscriber;
namespace Kanboard\Plugin\MyTheme\Subscriber;use Kanboard\Event\GenericEvent;
use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\CommentModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\TaskFileModel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;class MyNotificationSubscriber extends BaseSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
TaskModel::EVENT_USER_MENTION => ‘handleEvent’,
TaskModel::EVENT_CREATE => ‘handleEvent’,
TaskModel::EVENT_UPDATE => ‘handleEvent’,
TaskModel::EVENT_CLOSE => ‘handleEvent’,
TaskModel::EVENT_OPEN => ‘handleEvent’,
//TaskModel::EVENT_MOVE_COLUMN => ‘handleEvent’,
//TaskModel::EVENT_MOVE_PROJECT => ‘handleEvent’,
//TaskModel::EVENT_MOVE_POSITION => ‘handleEvent’,
//TaskModel::EVENT_MOVE_SWIMLANE => ‘handleEvent’,
TaskModel::EVENT_ASSIGNEE_CHANGE => ‘handleEvent’,
SubtaskModel::EVENT_CREATE => ‘handleEvent’,
//SubtaskModel::EVENT_UPDATE => ‘handleEvent’,
//SubtaskModel::EVENT_DELETE => ‘handleEvent’,
//CommentModel::EVENT_CREATE => ‘handleEvent’,
//CommentModel::EVENT_UPDATE => ‘handleEvent’,
//CommentModel::EVENT_DELETE => ‘handleEvent’,
CommentModel::EVENT_USER_MENTION => ‘handleEvent’,
TaskFileModel::EVENT_CREATE => ‘handleEvent’,
//TaskFileModel::EVENT_DESTROY => ‘handleEvent’,
//TaskLinkModel::EVENT_CREATE_UPDATE => ‘handleEvent’,
//TaskLinkModel::EVENT_DELETE => ‘handleEvent’,
);
}public function handleEvent(GenericEvent $event, $eventName) { $this->logger->debug('Subscriber executed: ' . __METHOD__); $this->queueManager->push($this->notificationJob->withParams($event, $eventName)); }
}
Yes, I forgot to add
use Kanboard\Subscriber\BaseSubscriber;
to my subscriber
But it still not working, in debug file I have [critical] MyTheme: Identifier “” is not defined.
Do you have workable notifications with this code?
I also tried to create a new plugin just for this function.
namespace Kanboard\Plugin\Test1;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Plugin\Test1\Subscriber\MyNotificationSubscriber;
But when I turn on this code in Plugin.php I have disappear my test plugin from the list of installed plugins.
$this->dispatcher->addSubscriber(new MyNotificationSubscriber($this->$container));
May be the problem in my KB version (1.2.12)?
You only could have one namspace.
The problem still exists. Could you take a look at it, I have already tested it several times and I really don’t know where I might have problems?
https://yadi.sk/d/4ygn695LCfj-Fw
Hi BlueTeck,
Please do not consider it rude and obsessive, but I really need help with it.
If anyone else can help me please take a look at the file. Or just let me know if my files work for your KB.