[Rt-commit] rt branch, 4.2/search-txn-and-queue-cfs, updated. rt-4.1.13-297-g66605ac
Thomas Sibley
trs at bestpractical.com
Fri Jul 12 23:42:22 EDT 2013
The branch, 4.2/search-txn-and-queue-cfs has been updated
via 66605aca809d39ae1592f8f40decae5198d1ba65 (commit)
from 404323355ad64d6a13515ce345cd2ebf45a8889b (commit)
Summary of changes:
lib/RT/Article.pm | 3 +--
lib/RT/CustomField.pm | 53 ++++++++++++++++++++++++++++++---------------------
2 files changed, 32 insertions(+), 24 deletions(-)
- Log -----------------------------------------------------------------
commit 66605aca809d39ae1592f8f40decae5198d1ba65
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Jul 12 20:32:38 2013 -0700
Rename RT::CustomField->_ForObjectType to RegisterLookupType
As custom fields are extensible by plugins and this method is called
outside of RT::CustomField even in core RT, it was already implicitly
public. Make it explicitly public and name it to match the
now-canonical name "lookup type". This is, after all, what the column
is called. "Register" matches the phrasing we've adopted elsewhere.
Renames and privatizes %FRIENDLY_OBJECT_TYPES as well to match. Other
code should access lookup type and friendly names via the API.
Deprecates _ForObjectType until 4.4.
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index 2f218c8..8670462 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -69,8 +69,7 @@ sub Table {'Articles'}
# This object takes custom fields
use RT::CustomField;
-RT::CustomField->_ForObjectType( CustomFieldLookupType() => 'Articles' )
- ; #loc
+RT::CustomField->RegisterLookupType( CustomFieldLookupType() => 'Articles' ); #loc
# {{{ Create
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 48f1ffa..b315abb 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -50,6 +50,7 @@ package RT::CustomField;
use strict;
use warnings;
+use 5.010;
use Scalar::Util 'blessed';
@@ -196,14 +197,13 @@ our %FieldTypes = (
my %BUILTIN_GROUPINGS;
-our %FRIENDLY_OBJECT_TYPES = ();
+my %FRIENDLY_LOOKUP_TYPES = ();
-RT::CustomField->_ForObjectType( 'RT::Queue-RT::Ticket' => "Tickets", ); #loc
-RT::CustomField->_ForObjectType(
- 'RT::Queue-RT::Ticket-RT::Transaction' => "Ticket Transactions", ); #loc
-RT::CustomField->_ForObjectType( 'RT::User' => "Users", ); #loc
-RT::CustomField->_ForObjectType( 'RT::Queue' => "Queues", ); #loc
-RT::CustomField->_ForObjectType( 'RT::Group' => "Groups", ); #loc
+__PACKAGE__->RegisterLookupType( 'RT::Queue-RT::Ticket' => "Tickets", ); #loc
+__PACKAGE__->RegisterLookupType( 'RT::Queue-RT::Ticket-RT::Transaction' => "Ticket Transactions", ); #loc
+__PACKAGE__->RegisterLookupType( 'RT::User' => "Users", ); #loc
+__PACKAGE__->RegisterLookupType( 'RT::Queue' => "Queues", ); #loc
+__PACKAGE__->RegisterLookupType( 'RT::Group' => "Groups", ); #loc
__PACKAGE__->RegisterBuiltInGroupings(
'RT::Ticket' => [ qw(Basics Dates Links People) ],
@@ -1117,15 +1117,9 @@ Returns an array of LookupTypes available
sub LookupTypes {
my $self = shift;
- return keys %FRIENDLY_OBJECT_TYPES;
+ return keys %FRIENDLY_LOOKUP_TYPES;
}
-my @FriendlyObjectTypes = (
- "[_1] objects", # loc
- "[_1]'s [_2] objects", # loc
- "[_1]'s [_2]'s [_3] objects", # loc
-);
-
=head2 FriendlyLookupType
Returns a localized description of the type of this custom field
@@ -1135,15 +1129,21 @@ Returns a localized description of the type of this custom field
sub FriendlyLookupType {
my $self = shift;
my $lookup = shift || $self->LookupType;
-
- return ($self->loc( $FRIENDLY_OBJECT_TYPES{$lookup} ))
- if (defined $FRIENDLY_OBJECT_TYPES{$lookup} );
+
+ return ($self->loc( $FRIENDLY_LOOKUP_TYPES{$lookup} ))
+ if defined $FRIENDLY_LOOKUP_TYPES{$lookup};
my @types = map { s/^RT::// ? $self->loc($_) : $_ }
grep { defined and length }
split( /-/, $lookup )
or return;
- return ( $self->loc( $FriendlyObjectTypes[$#types], @types ) );
+
+ state $LocStrings = [
+ "[_1] objects", # loc
+ "[_1]'s [_2] objects", # loc
+ "[_1]'s [_2]'s [_3] objects", # loc
+ ];
+ return ( $self->loc( $LocStrings->[$#types], @types ) );
}
=head1 RecordClassFromLookupType
@@ -1719,9 +1719,10 @@ sub ValuesForObject {
}
-=head2 _ForObjectType PATH FRIENDLYNAME
+=head2 RegisterLookupType LOOKUPTYPE FRIENDLYNAME
-Tell RT that a certain object accepts custom fields
+Tell RT that a certain object accepts custom fields via a lookup type and
+provide a friendly name for such CFs.
Examples:
@@ -1735,13 +1736,21 @@ This is a class method.
=cut
-sub _ForObjectType {
+sub RegisterLookupType {
my $self = shift;
my $path = shift;
my $friendly_name = shift;
- $FRIENDLY_OBJECT_TYPES{$path} = $friendly_name;
+ $FRIENDLY_LOOKUP_TYPES{$path} = $friendly_name;
+}
+sub _ForObjectType {
+ RT->Deprecated(
+ Instead => 'RegisterLookupType',
+ Remove => '4.4',
+ );
+ my $self = shift;
+ $self->RegisterLookupType(@_);
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list