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:
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
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