Answers.Body: <p>Not possible currently, but there's <a href="https://github.com/craftcms/cms/issues/1118" rel="nofollow noreferrer">a feature request</a>. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-29T23:45:21.520Z
Answers.LastActivityDate: 2017-02-25T04:51:21.643Z
Answers.LastEditDate: 2017-02-25T04:51:21.643Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-29T19:29:12.260Z
Answers.Text: 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 :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-29T21:23:23.050Z
Answers.Text: Awesome... I was going to suggest a feature request, then. :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-29T17:00:52.603Z
Answers.LastActivityDate: 2015-11-29T17:00:52.603Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugin-development><events>
Title: Is it possible to detach event listeners?
ThreadText: # 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](http://buildwithcraft.com/classreference/etc/web/WebApp#on-detail), 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 @username_1 – 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. :)  
  
  ---
  
  