custom/plugins/PickwareErpStarter/src/Reorder/Subscriber/BusinessEventCollectorSubscriber.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\PickwareErpStarter\Reorder\Subscriber;
  11. use InvalidArgumentException;
  12. use Pickware\PickwareErpStarter\Reorder\ReorderMailEvent;
  13. use Shopware\Core\Framework\Event\BusinessEventCollector;
  14. use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * Adds the event to the flow trigger list and allows the configuration of actions
  18.  * https://developer.shopware.com/docs/guides/plugins/plugins/framework/flow/add-flow-builder-trigger#add-your-new-event-to-the-flow-trigger-list
  19.  */
  20. class BusinessEventCollectorSubscriber implements EventSubscriberInterface
  21. {
  22.     private BusinessEventCollector $businessEventCollector;
  23.     public function __construct(BusinessEventCollector $businessEventCollector)
  24.     {
  25.         $this->businessEventCollector $businessEventCollector;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             BusinessEventCollectorEvent::NAME => [
  31.                 'onAddReorderMailEvent',
  32.                 1000// Adds the event before any other subscriber to prevent missing awareness or action
  33.             ],
  34.         ];
  35.     }
  36.     public function onAddReorderMailEvent(BusinessEventCollectorEvent $event): void
  37.     {
  38.         $collection $event->getCollection();
  39.         $definition $this->businessEventCollector->define(ReorderMailEvent::class);
  40.         if (!$definition) {
  41.             throw new InvalidArgumentException(sprintf(
  42.                 'Invalid business event in the class: %s',
  43.                 ReorderMailEvent::class,
  44.             ));
  45.         }
  46.         $collection->set($definition->getName(), $definition);
  47.     }
  48. }