createHookablesFor example

$this->hookableEventFactory = $this->getContainer()->get(HookableEventFactory::class);
    }

    public function testDoesNotCreateEventForConcreteBusinessEvent(): void
    {
        $factory = $this->getContainer()->get(FlowFactory::class);
        $event = $factory->create(new CustomerBeforeLoginEvent(
            $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL),
            'test@example.com'
        ));
        $event->setFlowState(new FlowState());
        $hookables = $this->hookableEventFactory->createHookablesFor($event);

        static::assertEmpty($hookables);
    }

    public function testDoesCreateHookableBusinessEvent(): void
    {
        $hookables = $this->hookableEventFactory->createHookablesFor(
            new TestFlowBusinessEvent(Context::createDefaultContext())
        );

        static::assertCount(1, $hookables);
        
 {
    }

    public function dispatch(object $event, ?string $eventName = null): object
    {
        $event = $this->dispatcher->dispatch($event$eventName);

        if (EnvironmentHelper::getVariable('DISABLE_EXTENSIONS', false)) {
            return $event;
        }

        foreach ($this->eventFactory->createHookablesFor($event) as $hookable) {
            $context = Context::createDefaultContext();
            if ($event instanceof FlowEventAware || $event instanceof AppChangedEvent || $event instanceof EntityWrittenContainerEvent) {
                $context = $event->getContext();
            }

            $this->callWebhooks($hookable$context);
        }

        // always return the original event and never our wrapped events         // this would lead to problems in the `BusinessEventDispatcher` from core         return $event;
    }
Home | Imprint | This part of the site doesn't use cookies.