1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
50 my $Type = $CustomField->Type;
52 # if we can't see the type, all hell will break loose.
53 $RT::Logger->error( "Custom field #". $CustomField->id ." has empty type" );
59 $Grouping =~ s/\W//g if $Grouping;
62 $Values = $Object->CustomFieldValues( $CustomField->id );
64 qw( id CustomField ObjectType ObjectId Disabled Content
65 ContentType ContentEncoding SortOrder Creator Created
66 LastUpdatedBy LastUpdated )
68 # Don't take care of $Values if there isn't values inside
69 undef ( $Values ) unless ( $Values->Count );
75 $Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
78 # Always fill $Default with submited values if it's empty
79 if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
80 my %TOP = %$DECODED_ARGS;
81 $Default = $TOP{ $Name } if $Name;
82 # check both -Values and -Value for back compatibility
84 $Default //= $TOP{ $NamePrefix . $CustomField->Id . '-Values' }
85 // $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
88 my $prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
89 $Default //= $TOP{ $prefix . 'Values' } // $TOP{ $prefix . 'Value' };
93 my $MaxValues = $CustomField->MaxValues;
94 if ($MaxValues == 1 && $Values) {
95 # what exactly is this doing? Without the "unless" it breaks RTFM
96 # transaction extraction into articles.
97 $Default = ($Values->First ? $Values->First->Content : '') unless $Default;
98 $Values->GotoFirstItem;
100 # The "Magic" hidden input causes RT to know that we were trying to edit the field, even if
101 # we don't see a value later, since browsers aren't compelled to submit empty form fields
102 $m->out("\n".'<input type="hidden" class="hidden" name="'
103 . ($Name ? $m->interp->apply_escapes($Name, 'h') : $m->interp->apply_escapes($NamePrefix, 'h').$CustomField->Id.'-Values')
104 . '-Magic" value="1" />'."\n");
107 my $EditComponent = "EditCustomField$Type";
108 $m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
109 $EditComponent = "EditCustomField$Type" unless $m->comp_exists($EditComponent);
119 MaxValues => $MaxValues,
120 Multiple => ($MaxValues != 1),
121 NamePrefix => $NamePrefix,
122 CustomField => $CustomField,
124 $CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
130 $CustomField => undef
135 $DefaultsFromTopArguments => 1,