Answers.Body: <p>Well, that's awkward.</p>
  
  <p>The <code>SetStatusEvent</code> was removed way back in the Craft 3.0 launch, but the class itself was never removed (will fix that for the upcoming 3.4 launch).</p>
  
  <p>There isn't really a clean replacement for it.</p>
  
  <p>One way would be to listen to the <code>EVENT_BEFORE_SAVE_ELEMENT</code> event, run a separate database query to get the current status from the database and compare the status to the element that was passed in to see if it changed.</p>
  
  <p>3.4 will give you another option - you could listen to <code>EVENT_AFTER_SAVE_ELEMENT</code>, then check the <code>dirtyAttributes</code> array to see if the status has changed, since elements now keep track of what attributes have changed on a given request.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-07T21:50:09.577Z
Answers.Text: In Craft 4 it looks like `status` does not appear in the dirtyAttributes array when I toggle "enabled" on an entry, even though `status` has definitely changed from `live` to `disabled`. However, `enabled` does appear in dirtyAttributes.
Answers.UserDisplayName: tremby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-09T00:30:51.093Z
Answers.LastActivityDate: 2020-01-09T00:30:51.093Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've been looking for an event that get triggered when an entry is moved from a disabled to enabled status.</p>
  
  <p>Currently I'm trying to find it through the <code>EVENT_AFTER_SAVE_ELEMENT</code> event but I have no idea what the previous status of the entry was so I can't tell if it was just updated:</p>
  
  <p><strong>current</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>Event::on(
      Elements::class,
      Elements::EVENT_AFTER_SAVE_ELEMENT,
      function(Event $event)
      {
          $element = $event-&gt;element;
  
          // Get the status, but I don't know the previous status.
          $status = $element-&gt;status;
      }
  );
  </code></pre>
  
  <p>I also had this pointed out to me <a href="https://docs.craftcms.com/api/v3/craft-events-setstatusevent.html" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-events-setstatusevent.html</a> but I don't know what emits this event as a parameter.</p>
  
Tags: <entries><events><status>
Title: Event when an entry is enabled
ThreadText: # Event when an entry is enabled
  
  (Asked by: username_0 on 2020-01-07)
  
  I've been looking for an event that get triggered when an entry is moved from a disabled to enabled status.
  
  Currently I'm trying to find it through the `EVENT_AFTER_SAVE_ELEMENT` event but I have no idea what the previous status of the entry was so I can't tell if it was just updated:
  
  **current**
  
  ```php
  Event::on(
      Elements::class,
      Elements::EVENT_AFTER_SAVE_ELEMENT,
      function(Event $event)
      {
          $element = $event->element;
  
          // Get the status, but I don't know the previous status.
          $status = $element->status;
      }
  );
  
  ```
  
  I also had this pointed out to me <https://docs.craftcms.com/api/v3/craft-events-setstatusevent.html> but I don't know what emits this event as a parameter.
  
  **Tags:** entries, events, status
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-09. Score: 2 | Accepted answer
  
  Well, that's awkward.
  
  The `SetStatusEvent` was removed way back in the Craft 3.0 launch, but the class itself was never removed (will fix that for the upcoming 3.4 launch).
  
  There isn't really a clean replacement for it.
  
  One way would be to listen to the `EVENT_BEFORE_SAVE_ELEMENT` event, run a separate database query to get the current status from the database and compare the status to the element that was passed in to see if it changed.
  
  3.4 will give you another option - you could listen to `EVENT_AFTER_SAVE_ELEMENT`, then check the `dirtyAttributes` array to see if the status has changed, since elements now keep track of what attributes have changed on a given request.
  
  > **Comments:**
  > **username_2**: In Craft 4 it looks like `status` does not appear in the dirtyAttributes array when I toggle "enabled" on an entry, even though `status` has definitely changed from `live` to `disabled`. However, `enabled` does appear in dirtyAttributes.  
  
  ---
  
  