<p>Not possible currently, but there's <a href="https://github.com/craftcms/cms/issues/1118" rel="nofollow noreferrer">a feature request</a>. </p>

CC BY-SA 3.0
2015-11-29T23:45:21.520Z
2017-02-25T04:51:21.643Z
2017-02-25T04:51:21.643Z
Mats Mikkel Rummelhoff
<p>Completely untested, and not sure if this will work with events registered with <a href="http://buildwithcraft.com/classreference/etc/web/WebApp#on-detail" rel="nofollow">on</a>, instead of the traditional Yii method, but try either:</p>

<pre><code>craft()-&gt;detachEventHandler('elements.onPopulateElements', array($this, 'elements.onPopulateElements'));
</code></pre>

<p>or:</p>

<pre><code>craft()-&gt;detachEventHandler('onPopulateElements', array($this, 'onPopulateElements'));
</code></pre>

<p>If neither of those work, then we'd need to add a custom <code>off</code> that takes into account the <code>componentName.event</code> event syntax that <code>on</code> users.</p>

CC BY-SA 3.0
2015-11-29T19:29:12.260Z
Thanks @Brad – unfortunately I wasn't able to make either of those work. The use case is that I only want/need the `elements.onPopulateElement` event handler to trigger one time (the event fires several times for most requests), so I figured the clean thing would be to detach the listener when the event fires the first time. I can put a flag in the event handler so no biggie, but an `off` method would be nice – I'll put up a feature request :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-11-29T21:23:23.050Z
Awesome... I was going to suggest a feature request, then. :)
Brad Bell
CC BY-SA 3.0
2015-11-29T17:00:52.603Z
2015-11-29T17:00:52.603Z
Brad Bell
<p>I've got an event listener hooked up like this:</p>

<pre><code>craft()-&gt;on('elements.populateElement', array($this, 'onPopulateElements'));
</code></pre>

<p>Is it possible to detach/deregister the listener? E.g. something like this (this doesn't work, but to illustrate):</p>

<pre><code>craft()-&gt;off('elements.populateElement', array($this, 'onPopulateElements'));
</code></pre>

<plugin-development><events>
Is it possible to detach event listeners?
# Is it possible to detach event listeners?

(Asked by: username_0 on 2015-11-29)

I've got an event listener hooked up like this:
craft()->on('elements.populateElement', array($this, 'onPopulateElements'));

Is it possible to detach/deregister the listener? E.g. something like this (this doesn't work, but to illustrate):
craft()->off('elements.populateElement', array($this, 'onPopulateElements'));

**Tags:** plugin-development, events


---

## 2 answers

### Answer by username_0 on 2015-11-29. Score: 2 | Accepted answer

Not possible currently, but there's [a feature request](https://github.com/craftcms/cms/issues/1118).


---

### Answer by username_1 on 2015-11-29. Score: 0

Completely untested, and not sure if this will work with events registered with on, instead of the traditional Yii method, but try either:
craft()->detachEventHandler('elements.onPopulateElements', array($this, 'elements.onPopulateElements'));

or:
craft()->detachEventHandler('onPopulateElements', array($this, 'onPopulateElements'));

If neither of those work, then we'd need to add a custom off that takes into account the componentName.event event syntax that on users.

> **Comments:**
> **username_0**: Thanks @Brad – unfortunately I wasn't able to make either of those work. The use case is that I only want/need the `elements.onPopulateElement` event handler to trigger one time (the event fires several times for most requests), so I figured the clean thing would be to detach the listener when the event fires the first time. I can put a flag in the event handler so no biggie, but an `off` method would be nice – I'll put up a feature request :)  
> **username_1**: Awesome... I was going to suggest a feature request, then. :)  

---

