Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [afinlr] form_link self->code bug

Quote Reply
Re: [afinlr] form_link self->code bug In reply to
As you have already noticed, the code in the original post is wrong in that the plugin hook only receives one argument (the opts hash ref). Because of that, the code is actually modifying $opts and not $self. Later on in the code, $opts's values actually replace anything set in $self, so that's why all the default code overrides stop working. As for your change, unfortunately, doing so would break any existing plugins (if there are any). Instead, I have fixed the core code to change $opts instead of $self. Here's a patch:
Code:
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Links.pm 29 Oct 2006 10:49:58 -0000 1.22
+++ Links.pm 22 Mar 2007 22:03:08 -0000 1.23
@@ -3,7 +3,7 @@
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
-# Revision : $Id: Links.pm,v 1.22 2006/10/29 10:49:58 brewt Exp $
+# Revision : $Id: Links.pm,v 1.23 2007/03/22 22:03:08 brewt Exp $
#
# Copyright (c) 2001 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
@@ -51,9 +51,13 @@
# Displays a record.
#
my ($self, $opts) = @_;
- $self->{code}->{LinkOwner} = \&disp_username;
- $self->{code}->{ExpiryDate} = \&disp_expiry;
- $self->{code}->{ExpiryCounted} = $self->{code}->{ExpiryNotify} = $self->{code}->{LinkExpired} = sub { '' };
+ $opts->{code}->{LinkOwner} ||= \&disp_username;
+ $opts->{code}->{ExpiryDate} ||= \&disp_expiry;
+
+ my $hidden = sub { '' };
+ $opts->{code}->{ExpiryCounted} ||= $hidden;
+ $opts->{code}->{ExpiryNotify} ||= $hidden;
+ $opts->{code}->{LinkExpired} ||= $hidden;

my $out = $self->SUPER::display($opts);
if ($opts->{mode} =~ /$SHOW_CAT_LIST/o) {
@@ -82,16 +86,13 @@

my $link_id = $opts->{values}->{ID} || $self->{input}->{ID};

-# Remove any previous code ref.
- delete $self->{code}->{LinkOwner};
-
# Hide fields we don't want to show on add/modify forms.
if ($opts->{mode} and $opts->{mode} =~ /$FORM_HIDE/o) {
$opts->{hide} ||= [];
push @{$opts->{hide}}, @{$FORM_HIDE_FIELDS};
}

- $self->{code}->{ExpiryDate} = \&form_expiry;
+ $opts->{code}->{ExpiryDate} ||= \&form_expiry;

# Add javascript to display the original values for text/textarea columns
if ($opts->{show_diff} and $link_id) {
@@ -126,8 +127,8 @@
next COL if $_ eq $col;
}

- if ((not defined $opts->{values}->{$col} or $current->{$col} ne $opts->{values}->{$col}) and !exists $self->{code}->{$col}) {
- $self->{code}->{$col} = $textarea;
+ if ((not defined $opts->{values}->{$col} or $current->{$col} ne $opts->{values}->{$col}) and not $opts->{code}->{$col}) {
+ $opts->{code}->{$col} = $textarea;
}
}
}

It won't patch cleanly against 3.2 since there have been a few other changes in the file since then, but the idea is there.

Adrian
Subject Author Views Date
Thread form_link self->code problem klangan 8184 Jun 9, 2005, 1:42 PM
Thread Re: [klangan] form_link self->code problem
afinlr 8068 Jul 19, 2005, 3:00 PM
Thread Re: [afinlr] form_link self->code bug
klangan 8083 Jul 19, 2005, 3:17 PM
Post Re: [klangan] form_link self->code bug
afinlr 8052 Jul 19, 2005, 3:20 PM
Thread Re: [klangan] form_link self->code bug
afinlr 7935 Mar 22, 2007, 11:39 AM
Thread Re: [afinlr] form_link self->code bug
klangan 7930 Mar 22, 2007, 1:41 PM
Thread Re: [klangan] form_link self->code bug
afinlr 7933 Mar 22, 2007, 2:24 PM
Thread Re: [afinlr] form_link self->code bug
klangan 7929 Mar 22, 2007, 2:50 PM
Post Re: [klangan] form_link self->code bug
afinlr 7937 Mar 22, 2007, 3:01 PM
Thread Re: [afinlr] form_link self->code bug
brewt 7928 Mar 22, 2007, 3:27 PM
Thread Re: [brewt] form_link self->code bug
afinlr 7911 Mar 22, 2007, 4:36 PM
Thread Re: [afinlr] form_link self->code bug
brewt 7913 Mar 22, 2007, 4:41 PM
Post Re: [brewt] form_link self->code bug
afinlr 7904 Mar 22, 2007, 5:18 PM
Thread Re: [brewt] form_link self->code bug
afinlr 7899 Mar 24, 2007, 12:42 PM
Thread Re: [afinlr] form_link self->code bug
afinlr 7899 Mar 24, 2007, 6:20 PM
Thread Re: [afinlr] form_link self->code bug
afinlr 7892 Mar 24, 2007, 8:27 PM
Post Re: [afinlr] form_link self->code bug
afinlr 7901 Mar 25, 2007, 11:18 AM