chrzanek98 / pimcore-object-event-listeners-bundle
This bundle lets create event listeners for pimcore DataObjects in easy and flexible way
Installs: 87
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.6.0
- pimcore/pimcore: 5.*
This package is auto-updated.
Last update: 2024-10-29 05:34:21 UTC
README
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute:
$ composer require chrzanek98/pimcore-object-event-listeners-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new \Chrzanek98\PimcoreObjectEventListenersBundle\Chrzanek98PimcoreObjectEventListenersBundle(), ); // ... } // ... }
How it works?
Step 1
Create handler class e.g. AcmeEventListener.php and extend it with AbstractHandler
<?php namespace AppBundle\EventListeners; use Chrzanek98\PimcoreObjectEventListenersBundle\EventListeners\Providers\AbstractHandler; use Pimcore\Event\Model\DataObjectEvent; class AcmeEventListener extends AbstractHandler { // ... }
Step 2
Implement canHandle method
<?php namespace AppBundle\EventListeners; // ... class AcmeEventListener extends AbstractHandler { public function canHandle(DataObjectEvent $element) { return $element->getObject() instanceof Acme; } }
Step 3
Use desired hook, currently available are pre/post Add/Update/Delete
<?php namespace AppBundle\EventListeners; // ... class AcmeEventListener extends AbstractHandler { public function preUpdate(DataObjectEvent $element) { throw new NotFoundHttpException('Lorem ipsum dolor sit amet'); } public function canHandle(DataObjectEvent $element) { return $element->getObject() instanceof Acme; } }
Step 4
Register your event handler as a service with tag object.handler
object.handler.acme: class: AppBundle\EventListeners\AcmeEventListener tags: - { name: object.handler }