3

I am writing an extension for the hook

entry_submission_ready

I see that it has 3 params(meta, data, autosave).

I look at data and I see there is channel data in there and a revision post data index.

I assumed that the revision post data contains the old, not updated data.

But when I compared then to the top level data, they are the same. Both also show the updated data.

Is there any way I can access the old data? Do I need to use a different hook?

How do I know if a field value has been changed by edits?

  • 1. isn't revision data only available when revisions are enabled on a channel? 2. To make sure if data is changed by an edit: a) store a copy of the field data at, say, the publish_form_entry_data() hook and check it on entry_submission_ready, or b) check against the database after submit. – GDmac Feb 13 '13 at 9:59
  • @GDmac good suggestions. Will try some of your solutions. – developarvin Feb 14 '13 at 1:40
4

That hook gives you all the data you need to query the database. $meta will hold your entry_id, channel_id, title, etc (anything that goes in exp_channel_titles), and $data holds your custom field data.

So just as an example:

if(!empty($meta['entry_id']))
{
    $current = $this->EE->db->query("
        SELECT * FROM exp_channel_data WHERE entry_id = {$meta['entry_id']} LIMIT 1
    ");
    if($current->num_rows() == 1)
    {
        if($data['field_id_1'] === $current->row('field_id_1'))
        {
            // Data has not changed in field_id_1
         }
    }
}
| improve this answer | |
  • Ok, so your solution basically means that I should compare $data with the database values using entry id as the key. I will try if it works. – developarvin Feb 14 '13 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.