X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FCustomField.pm;h=e71bbf78adb50f1517bd59d60dbf1cf21619856b;hb=b8988e1d3ac75af63c85e8563e57701030315a9e;hp=01b4970c4faf20b5b0262beca42c63ecce12083b;hpb=7f029e082712dceafb9152820746da79a50f2275;p=freeside.git diff --git a/rt/lib/RT/CustomField.pm b/rt/lib/RT/CustomField.pm index 01b4970c4..e71bbf78a 100644 --- a/rt/lib/RT/CustomField.pm +++ b/rt/lib/RT/CustomField.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -51,7 +51,7 @@ package RT::CustomField; use strict; use warnings; - +use Scalar::Util 'blessed'; use base 'RT::Record'; @@ -1111,11 +1111,6 @@ sub SetRenderType { $self->FriendlyType)); } - # XXX: Remove this restriction once we support lists and cascaded selects - if ( $self->BasedOnObj->id and $type =~ /List/ ) { - return (0, $self->loc("We can't currently render as a List when basing categories on another custom field. Please use another render type.")); - } - return $self->_Set( Field => 'RenderType', Value => $type, @_ ); } @@ -1193,7 +1188,7 @@ Returns an array of LookupTypes available sub LookupTypes { my $self = shift; - return keys %FRIENDLY_OBJECT_TYPES; + return sort keys %FRIENDLY_OBJECT_TYPES; } my @FriendlyObjectTypes = ( @@ -1222,14 +1217,57 @@ sub FriendlyLookupType { return ( $self->loc( $FriendlyObjectTypes[$#types], @types ) ); } +=head1 RecordClassFromLookupType + +Returns the type of Object referred to by ObjectCustomFields' ObjectId column + +Optionally takes a LookupType to use instead of using the value on the loaded +record. In this case, the method may be called on the class instead of an +object. + +=cut + sub RecordClassFromLookupType { my $self = shift; - my ($class) = ($self->LookupType =~ /^([^-]+)/); + my $type = shift || $self->LookupType; + my ($class) = ($type =~ /^([^-]+)/); unless ( $class ) { - $RT::Logger->error( - "Custom Field #". $self->id - ." has incorrect LookupType '". $self->LookupType ."'" - ); + if (blessed($self) and $self->LookupType eq $type) { + $RT::Logger->error( + "Custom Field #". $self->id + ." has incorrect LookupType '$type'" + ); + } else { + RT->Logger->error("Invalid LookupType passed as argument: $type"); + } + return undef; + } + return $class; +} + +=head1 ObjectTypeFromLookupType + +Returns the ObjectType used in ObjectCustomFieldValues rows for this CF + +Optionally takes a LookupType to use instead of using the value on the loaded +record. In this case, the method may be called on the class instead of an +object. + +=cut + +sub ObjectTypeFromLookupType { + my $self = shift; + my $type = shift || $self->LookupType; + my ($class) = ($type =~ /([^-]+)$/); + unless ( $class ) { + if (blessed($self) and $self->LookupType eq $type) { + $RT::Logger->error( + "Custom Field #". $self->id + ." has incorrect LookupType '$type'" + ); + } else { + RT->Logger->error("Invalid LookupType passed as argument: $type"); + } return undef; } return $class;