Is there a hook that could be used to check what status was before submission, and what status is submitted (changed to) whilst editing an entry?
I want to check to see if a status is changed to 'x2' from 'x1' for example.
Thanks
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityI would use the
entry_submission_ready
extension hook, and write a mini-extension that looks at the meta array in the api for the entry status value, and compares it to the previous value for that entry (if it exists). Quick example hook function that could work for your situation:
function entry_submission_ready_my_hook($meta, $data, $autosave)
{
// get entry_status and entry_id if it exists
$new_status = $meta['status'];
$entry_id = $data['entry_id'];
// check if the entry exists
$entry = ee()->db->select('status')
->from('channel_titles')
->where('entry_id', $entry_id)
->get();
// do we have an entry and is it's status different?
if ( ( $entry->num_rows() > 0 ) &&
( $entry->status !== $new_status ) )
{
// we have different entry status! do stuff here!
}
}
The above code is completely untested, but that's the idea and should work just fine for your needs.