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

How do I actually modify data using an extension hook?

Development and Programming

Ben Parizek's avatar
Ben Parizek
128 posts
13 years ago
Ben Parizek's avatar Ben Parizek

I got a noob extension development question here. I’m trying to modify some data upon submission of an entry for. I want to take the data from one field that is being submitted, check if certain conditions exist, and then update another field. I’m able to get the extension set up fine, and I’m able to see the data I want to work with when I vardump it within the main extension function. I’m even able to modify it, run the query I want, and update the data I want. I can see the change is taking place when I vardump the values after I make the modification.

But, how do I return the data so that it actual changes? I’ve tried several versions of “return” to no avail.

Bonus points:

From what I’ve described above, which of the hooks below do I want to be using?

function publish_form_entry_data($row)
{

}

And, in this extension hook, if I wanted to modify a value from the $meta AND the $data arrays, could I return both of those values in a modified form or can I only return one of those arrays?

function entry_submission_absolute_end($entry_id, $meta, $data)
{

}

If you could let me know what I’m missing, I’d appreciate it. I’m probably misunderstanding some fundamental element here. Cheers.

       
Bhashkar Yadav's avatar
Bhashkar Yadav
726 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

you should use hook entry_submission_ready.

       
Ben Parizek's avatar
Ben Parizek
128 posts
13 years ago
Ben Parizek's avatar Ben Parizek

Ok. So I guess the $this->autosave value the one that does the saving for me?

       
Bhashkar Yadav's avatar
Bhashkar Yadav
726 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Ben, i hope so. did you try this ?

       
Ben Parizek's avatar
Ben Parizek
128 posts
13 years ago
Ben Parizek's avatar Ben Parizek

Sorry Bhashkar, I’m still not figuring this out. A simplified example of how to modify a value would be useful. I clearly don’t have the right mental model of what I’m trying to do.

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

I also have the same problem.

IMO, modifying field values upon saving or editing is one of the most common things that extension is used for.

So I don’t see why this hasn’t been answered yet.

       
Ben Parizek's avatar
Ben Parizek
128 posts
12 years ago
Ben Parizek's avatar Ben Parizek

Hey Arvinsim. I finally did figure out how to do this. I don’t remember the exact details but I don’t believe it was possible to modify the data in the way I was describing above. I ended up grabbing the entry_id from one of the hooks and then wrote a separate query and just interfaced with the database directly to update the data.

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

Have you tried looking at the source from where the hook is called? In the api for channel entries, the hook is called with $this->data if you want to manipulate said data, have you tried using a reference?

function my_hook_catch( &$string, $foo='')
{
    $foo = 'passed by value';
    $string .= 'passed by reference';
}

$str = 'This is a string, ';
my_hook_catch($str);
echo $str;    

// outputs 'This is a string, passed by reference'
// example 2 on http://php.net/manual/en/functions.arguments.php
       

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.