Event subscribers' registration

Edit on GitHub

Manifests support registering event subscribers only in the dependency provider, a type of code class.

The following is an example of how to register event subscribers in collection with parent method call in a dependency provider:

use Spryker\Zed\AvailabilityStorage\Communication\Plugin\Event\Subscriber\AvailabilityStorageEventSubscriber;
use Spryker\Zed\Event\EventDependencyProvider as SprykerEventDependencyProvider;
use Spryker\Zed\UrlStorage\Communication\Plugin\Event\Subscriber\UrlStorageEventSubscriber;

class EventDependencyProvider extends SprykerEventDependencyProvider
{
    ...
    protected function getEventSubscriberCollection()
    {
        $collection = parent::getEventSubscriberCollection();

        $collection->add(new AvailabilityStorageEventSubscriber());
        $collection->add(new UrlStorageEventSubscriber());

        return $collection;
    }
}

Manifests fully support the registration of event subscribers in the collection. Restrictions to the order of the plugins in collection are not supported. New plugin is added to the end of the collection.

The following is an example of how to register event subscribers in collection with a chain of method calls in a dependency provider:

use Spryker\Zed\AvailabilityStorage\Communication\Plugin\Event\Subscriber\AvailabilityStorageEventSubscriber;
use Spryker\Zed\Event\EventDependencyProvider as SprykerEventDependencyProvider;
use Spryker\Zed\UrlStorage\Communication\Plugin\Event\Subscriber\UrlStorageEventSubscriber;

class EventDependencyProvider extends SprykerEventDependencyProvider
{
    ...
    protected function getEventSubscriberCollection()
    {
        $collection = parent::getEventSubscriberCollection();

        $collection->add(new AvailabilityStorageEventSubscriber())
            ->add(new UrlStorageEventSubscriber());

        return $collection;
    }
}