We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Head-scratcher: manipulating new/updated entries after submission

Development and Programming

Derek Hogue's avatar
Derek Hogue
317 posts
15 years ago
Derek Hogue's avatar Derek Hogue

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!

       
Derek Hogue's avatar
Derek Hogue
317 posts
15 years ago
Derek Hogue's avatar Derek Hogue

Update on this, in case anyone cares. I ended up defining a constant to use as a check against the endless loop, as it stays defined throughout the processing.

       
Shann McNicholl's avatar
Shann McNicholl
2 posts
15 years ago
Shann McNicholl's avatar Shann McNicholl

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

       
Derek Hogue's avatar
Derek Hogue
317 posts
15 years ago
Derek Hogue's avatar Derek Hogue

Indeed Shann, thanks – I did sort that just last week when sleuthing-around in someone else’s add-on that used the same hook. Felt like an idiot that’s for sure! Not too well-versed in OOP, but it makes perfect sense.

       
Electric Putty's avatar
Electric Putty
88 posts
15 years ago
Electric Putty's avatar Electric Putty

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

       
Derek Hogue's avatar
Derek Hogue
317 posts
15 years ago
Derek Hogue's avatar Derek Hogue

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.

       
Electric Putty's avatar
Electric Putty
88 posts
15 years ago
Electric Putty's avatar Electric Putty

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

       
adisys's avatar
adisys
23 posts
14 years ago
adisys's avatar adisys

Can you guys post a working version of the method code? I am struggling with this as well..

       
Derek Hogue's avatar
Derek Hogue
317 posts
14 years ago
Derek Hogue's avatar Derek Hogue

What specifically are you trying to do adisys?

       
arvinsim's avatar
arvinsim
23 posts
13 years ago
arvinsim's avatar arvinsim

Is there an answer to this?

       
GDmac - expocom's avatar
GDmac - expocom
350 posts
13 years ago
GDmac - expocom's avatar GDmac - expocom

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

       
Derek Hogue's avatar
Derek Hogue
317 posts
13 years ago
Derek Hogue's avatar Derek Hogue

Good call GDmac, I’ll have to test that.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.