Skip to content

Instantly share code, notes, and snippets.

@chluehr
Created June 15, 2015 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chluehr/4148e24f9dd64bf9e06f to your computer and use it in GitHub Desktop.
Save chluehr/4148e24f9dd64bf9e06f to your computer and use it in GitHub Desktop.
Sample: Replace Backend Pimcore Search Hooks - Detach ZF1 EventManager Listeners / Callbacks
<?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