Answers.Body: <p>As you've discovered, you should be using the more generic <a href="https://craftcms.com/docs/plugins/events-reference#elements-onBeforePerformAction" rel="nofollow">elements.onBeforePerformAction</a> or <a href="https://craftcms.com/docs/plugins/events-reference#elements-onPerformAction" rel="nofollow">elements.onPerformAction</a> events.  They get fired when <em>any</em> action takes place and you can check their <code>action</code> parameter to determine if it was a <code>SetStatus</code> action.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-23T18:40:33.987Z
Answers.LastActivityDate: 2015-12-23T18:40:33.987Z
Answers.UserDisplayName: Brad Bell
Body: <p>I wanted to listen to the <code>onSetStatus</code> event of the <code>SetStatusElementAction</code> and used the same code like in the <code>EntryElementType</code> class:</p>
  
  <pre><code>$setStatusAction = craft()-&gt;elements-&gt;getAction('SetStatus');
  $setStatusAction-&gt;onSetStatus = function(Event $event) {
    MyPlugin::log('maybe');
  }
  </code></pre>
  
  <p>But it didn't work and I had to hack into the core making following code changes:</p>
  
  <p>in the <code>ElementsService</code> class:</p>
  
  <pre><code>/**
   * Fires an 'onSetStatus' event.
   *
   * @param Event $event
   *
   * @return null
   */
  public function onSetStatus(Event $event)
  {
      $this-&gt;raiseEvent('onSetStatus', $event);
  }
  </code></pre>
  
  <p>in the <code>EntryElementType::getAvailableActions</code> method where the <code>onSetStatus</code> is called:</p>
  
  <pre><code>craft()-&gt;elements-&gt;onSetStatus($event);
  </code></pre>
  
  <p>This way I'm able to listen to the event in my plugin:</p>
  
  <pre><code>craft()-&gt;on('elements.setStatus', function() { ... });
  </code></pre>
  
  <p>The problem is that with the next update I have to do the code changes again. Is there a better way to listen to the event or is this worth a push request?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-12-23T14:15:55.460Z
Comments.Text: Craft 2.5.2750 seems to have introduced the `elements.onPerformAction` and `elements.onBeforePerformAction` events
Comments.UserDisplayName: oncode
Tags: <plugin-development><entry><services><status>
Title: Listen to onSetStatus event
ThreadText: # Listen to onSetStatus event
  
  (Asked by: username_0 on 2015-12-23)
  
  I wanted to listen to the `onSetStatus` event of the `SetStatusElementAction` and used the same code like in the `EntryElementType` class:
  
  ```
  $setStatusAction = craft()->elements->getAction('SetStatus');
  $setStatusAction->onSetStatus = function(Event $event) {
    MyPlugin::log('maybe');
  }
  
  ```
  
  But it didn't work and I had to hack into the core making following code changes:
  
  in the `ElementsService` class:
  
  ```
  /**
   * Fires an 'onSetStatus' event.
   *
   * @param Event $event
   *
   * @return null
   */
  public function onSetStatus(Event $event)
  {
      $this->raiseEvent('onSetStatus', $event);
  }
  
  ```
  
  in the `EntryElementType::getAvailableActions` method where the `onSetStatus` is called:
  
  ```
  craft()->elements->onSetStatus($event);
  
  ```
  
  This way I'm able to listen to the event in my plugin:
  
  ```
  craft()->on('elements.setStatus', function() { ... });
  
  ```
  
  The problem is that with the next update I have to do the code changes again. Is there a better way to listen to the event or is this worth a push request?
  
  **Tags:** plugin-development, entry, services, status
  
  > **Comments:**
  > **username_0**: Craft 2.5.2750 seems to have introduced the `elements.onPerformAction` and `elements.onBeforePerformAction` events  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-23. Score: 2 | Accepted answer
  
  As you've discovered, you should be using the more generic [elements.onBeforePerformAction](https://craftcms.com/docs/plugins/events-reference#elements-onBeforePerformAction) or [elements.onPerformAction](https://craftcms.com/docs/plugins/events-reference#elements-onPerformAction) events. They get fired when *any* action takes place and you can check their `action` parameter to determine if it was a `SetStatus` action.
  
  
  ---
  
  