Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Accessing modify_link as a POST hook?

Quote Reply
Accessing modify_link as a POST hook?
Hi,

This issue has been a thorn in my side for a while now. It seems that when doing a modify_link PRE hook, we get ALL the link info passed into the function with @_ ... but when doing it using a POST hook, all that gets passed along is 1 ... why is this? I've checked that there are no other plugins accessing modify_link (in case they were not passing back @args properly), and and thats not the case. The only way I seem to be able to do what I'm trying - is to edit /Table/Links.pm:

Code:
$CUSTOM::LID = $id; # HACK
return $ret;

Then in my plugin POST hook, I can use:

Code:
sub admin_modify_link {

# I have to custom pass a value with the LinkID in it - otherwise we can't get it in POST modify_link hook!
print "BLA: $CUSTOM::LID ";

return @_;
}

Surely the PRE hook is done BEFORE we actually do the update... so in cases like mine (where I want to run stuff AFTER its been updated), this doesn't work? My "hack" will work for the mean time, but when I come to update a couple of my plugins it would be to have this fixed up Smile

Oh, and FWIW add_link DOES return the link_id into $_[0] in the POST hook - that all I'm after Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Aug 24, 2012, 9:12 AM
Quote Reply
Re: [Andy] Accessing modify_link as a POST hook? In reply to
Oh, and another thing - should the POST hook only run when the update was successful? Cos ATM it seems to run no matter what.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Accessing modify_link as a POST hook? In reply to
Unfortunately, a POST hook only gets passed in the return value(s) of the function and then the return value of your POST hook is used as the final return value.

If you need to save input, then one way to get around it would be to save it using a PRE hook, or just use $IN (if applicable) to get your data.

Adrian
Quote Reply
Re: [Andy] Accessing modify_link as a POST hook? In reply to
Andy wrote:
Oh, and another thing - should the POST hook only run when the update was successful? Cos ATM it seems to run no matter what.

It runs no matter what. It's up to you to check the return value to determine if your PRE hook code should run.

Adrian
Quote Reply
Re: [brewt] Accessing modify_link as a POST hook? In reply to
Hi,

Ah ok - thanks. Not sure why I didn't think of doing a $IN->param( 'foo' => xxx ) to set the value in the PRE... thanks for the suggestion Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [brewt] Accessing modify_link as a POST hook? In reply to
Ok thanks for the info.I guess in that case it would be best to do something like this in the PRE:

Code:
if ($_[0]->{error}) {
$IN->param('do_run' => 0 );
} else {
$IN->param('do_run' => 1 );
$IN->param('linkid' => $_[0]->{ID} );
}

I'll have a play with that and see what I can come up with. Thanks Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!