I’m working on a port of one of my 1.6 extensions, and it requires me manipulating some entry data after submission. Previously, I simply worked on the $_POST array using submit_new_entry_start.
I started off trying entry_submission_start, but then saw that the $_POST array had already been pulled into the new $data array at that point, which I didn’t have access to, and which is used when inserting/updating the entry. So working with the $_POST array was fruitless.
So I moved on to entry_submission_ready, which has the $data and $meta arrays passed to it. Great, I can work on the field values there … except all that data never makes it back to the Channel Entries API for insertion. (I can only assume this hook is for taking that data elsewhere, a custom module table or what have you.)
OK, so I moved on to entry_submission_end, deciding that I’d take the existing entry data and entry_id, and use the Channel Entries API to then immediately update the just-created/edited entry with my modified field values. This works, but then I end up in an endless loop, as I’m calling an update_entry() on a hook that’s called at the end of every update_entry().
I tried using a class variable to hold whether the update had run already, and stop if it had, but I guess that gets reset every time the hook is called and the class is re-instantiated.
So my question is … anyone have a brilliant idea on a way around this? And is this really the only way to work on $_POSTed field data before it gets into the database (or, in this case, after)?
Any help or ideas would be great!
did you get sorted with this? Annoyed me for the last hour.
$this->ee->api_sc_channel_entries->data[]
…contains the data that you are sent in the entry_submission_ready hook. You can manipulate this directly and the amendments will be saved in the DB as expected.
No reason for this to be so convoluted.
Anyways - if this doesn’t help you - it’ll help all the googlers…
Thanks,
Shann
Hi D-Rock,
I am facing a very similar dilemma. I posted about it here: http://ellislab.com/forums/viewthread/184077/
Since I wrote this I have tried manipulating the data array using entry_submission_start hook so that relationship entries are identical to what is already in the DB, this way the _build_relationships() method doesn’t change anything. I then replace the new values using the entry_submission_ready hook.
So far so good, this fixes one issue.
The problem I have now is that I end up the the endless loop you describe. I’m not 100% sure how to go about setting a constant to prevent this. I wonder if you could point me in the right direction?
Many thanks,
Malcolm
Hey Malcolm - the key is to indeed use entry_submission_start and work with $this->ee->api_channel_entries->data[] instead of anything you’re passed by the hook. You can read and write values from and to that array from within the hook.
I was encountering this loop because I was running another api_channel_entries call within entry_submision_ready, which in turn was calling entry_submission_ready again. If you stay way from running api_channel_entries within the hook, you should be OK.
Hi D-Rock,
Many thanks for the sanity check.
I pretty much got there myself. Once I realised the data array was read / writeable I was able to manipulate the data as needed using entry_submission_start.
The only tricky part was that in certain circumstances I wanted to go ahead and run a normal update and I was trying to do this using a call to the api_channel_entries from the entry_submission_ready hook.
The answer to to simply do nothing. In those circumstances just return from this hook and let the original update do its thing.
Best wishes,
Malcolm
Derek, instead of altering the $this->ee->api_channel_entries->data[] variable, if you look at the api itself, it already uses $this->data =& $data; and passes this->data when calling the hooks. so i guess you could try to maybe pass the function parameter by reference.
see: http://ellislab.com/forums/viewthread/210027/#1047804
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.