Channels
Note
此页面的内容需要进行重大更新。旧页面包含过时且可能不准确的信息。您仍然可以通过 Mautic Developer Documentation archived repository 访问它。
如果您有兴趣帮助开发此页面和其他新内容的,请考虑加入文档编写工作。
请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。
Listening for Channel features
您可以通过 ChannelEvents 类找到几个事件。
<?php
public static function getSubscribedEvents()
{
return [
ChannelEvents::ADD_CHANNEL => ['onAddChannel', 100],
];
}
public function onAddChannel(ChannelEvent $event)
{
$event->addChannel(
'email',
[
MessageModel::CHANNEL_FEATURE => [
'campaignAction' => 'email.send',
'campaignDecisionsSupported' => [
'email.open',
'page.pagehit',
'asset.download',
'form.submit',
],
'lookupFormType' => EmailListType::class,
],
LeadModel::CHANNEL_FEATURE => [],
ReportModel::CHANNEL_FEATURE => [
'table' => 'emails',
],
]
);
}
Extending broadcasts
Broadcasts are communications sent in bulk through a Channel such as Email.
An event is available to execute the sending of these bulk communications via the mautic:broadcasts:send command.
To hook into the mautic:broadcasts:send command, create a listener for the \Mautic\CoreBundle\CoreEvents::CHANNEL_BROADCAST event.
The event listener should check for the appropriate context and ID.
<?php
// plugins\HelloWorldBundle\EventListener\BroadcastSubscriber
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\ChannelBundle\ChannelEvents;
use Mautic\ChannelBundle\Event\ChannelBroadcastEvent;
use MauticPlugin\HelloWorldPlugin\Model\WorldModel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class BroadcastSubscriber implements EventSubscriberInterface
{
private WorldModel $model;
public function __construct(WorldModel $model)
{
$this->model = $model;
}
public static function getSubscribedEvents(): array
{
return [
ChannelEvents::CHANNEL_BROADCAST => ['onChannelBroadcast', 0]
];
}
- public function onChannelBroadcast(ChannelBroadcastEvent $event): void
- {
- if (!$event->checkContext(‘world’)) {
return;
}
// Get list of published broadcasts or broadcast if there is only a single ID $id = $event->getId(); $broadcasts = $this->model->getRepository()->getPublishedBroadcasts($id); $output = $event->getOutput();
- while (($broadcast = $broadcasts->next()) !== false) {
list($sentCount, $failedCount, $ignore) = $this->model->sendIntergalacticMessages($broadcast[0], null, 100, true, $output); $event->setResults($this->translator->trans(‘plugin.helloworld’).’: ‘.$broadcast[0]->getName(), $sentCount, $failedCount);
}
}
}