Created
June 15, 2015 21:36
-
-
Save chluehr/4148e24f9dd64bf9e06f to your computer and use it in GitHub Desktop.
Sample: Replace Backend Pimcore Search Hooks - Detach ZF1 EventManager Listeners / Callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ElasticFind; | |
use Pimcore\API\Plugin as PluginLib; | |
class Plugin extends PluginLib\AbstractPlugin implements PluginLib\PluginInterface { | |
public function init() { | |
parent::init(); | |
// remove old event listeners for search: | |
foreach (["asset","object","document"] as $type) { | |
foreach (["postUpdate","postAdd","preDelete"] as $method) { | |
$listeners = \Pimcore::getEventManager()->getListeners($type . "." . $method); | |
foreach ($listeners->getIterator() as $listener) { | |
$callback = $listener->getCallback(); | |
if (get_class($callback[0]) == 'Pimcore\Model\Search\Backend\Module') { | |
if (\Pimcore::getEventManager()->detach($listener)) | |
{ | |
//echo "DETACHED!"; | |
} | |
} | |
} | |
} | |
} | |
// attach new event-listeners | |
\Pimcore::getEventManager()->attach("object.postUpdate", array($this, "postUpdateElement")); | |
/* | |
foreach (["asset","object","document"] as $type) { | |
\Pimcore::getEventManager()->attach($type . ".postAdd", array($this, "postAddElement")); | |
\Pimcore::getEventManager()->attach($type . ".postUpdate", array($this, "postUpdateElement")); | |
\Pimcore::getEventManager()->attach($type . ".preDelete", array($this, "preDeleteElement")); | |
} | |
*/ | |
} | |
public function postUpdateElement($event) { | |
// do something | |
$object = $event->getTarget(); | |
var_dump($object); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment