<?php declare(strict_types=1);
namespace Cogi\CogiAdvancedContactForm\Subscriber;
use Cogi\CogiAdvancedContactForm\Core\Event\CogiAdvancedContactFormSubmitEvent;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEventCollectorSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
public function __construct(BusinessEventCollector $businessEventCollector) {
$this->businessEventCollector = $businessEventCollector;
}
public static function getSubscribedEvents()
{
return [
BusinessEventCollectorEvent::NAME => ['onAddCogiFormEvents', 1000],
];
}
public function onAddCogiFormEvents(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$eventClasses = [
CogiAdvancedContactFormSubmitEvent::class,
];
foreach($eventClasses as $eventClass) {
$definition = $this->businessEventCollector->define($eventClass);
if (!$definition) {
continue;
}
$collection->set($definition->getName(), $definition);
}
}
}