Skip to content

Commit

Permalink
Support to skip label for EditCustomField
Browse files Browse the repository at this point in the history
We added label support in 701adc6. Sadly that there are still cases where
we only want the value part, like in RT::Extension::FormTools extension.
  • Loading branch information
sunnavy committed Feb 13, 2025
1 parent bb88aca commit c61d33b
Showing 1 changed file with 88 additions and 61 deletions.
149 changes: 88 additions & 61 deletions share/html/Elements/EditCustomField
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,96 @@
%#
%# END BPS TAGGED BLOCK }}}

% if ( $ShowLabel ) {
<&| /Elements/LabeledValue,
Label => ( $Label ? $Label : $CustomField->Name ),
LabelFor => $Name,
LabelTooltip => $CustomField->EntryHint,
FormText => $FormText &>
<& SELF:Content, %ARGS, Name => $Name, Default => $Default, CFHintId => $CFHintId &>
</&>
% } else {
<& SELF:Content, %ARGS, Name => $Name, Default => $Default, CFHintId => $CFHintId &>
% }

<%INIT>
my $Type = $CustomField->Type;
unless ( $Type ) {
# if we can't see the type, all hell will break loose.
$RT::Logger->error( "Custom field #". $CustomField->id ." has empty type" );
return;
}

$Grouping =~ s/\W//g if $Grouping;
my $Name;
if ( !$NamePrefix ) {
$Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
}

my $CFHintId;
my $cf_name_prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );

if ($ShowHints and $CustomField->FriendlyPattern) {
$CFHintId = $cf_name_prefix . 'Hint';
}

# Always fill $Default with submited values if it's empty
if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
my %TOP = %$DECODED_ARGS;
$Default = $TOP{ $Name } if $Name;
# check both -Values and -Value for back compatibility
if ( $NamePrefix ) {
$Default //= $TOP{ $NamePrefix . $CustomField->Id . '-Values' }
// $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
}
else {
$Default //= $TOP{ $cf_name_prefix . 'Values' } // $TOP{ $cf_name_prefix . 'Value' };
}
}

if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
$Default = $CustomField->DefaultValues(Object => $on || RT->System);
}

my $FormText;
if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

</%INIT>
<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$ShowLabel => 1
</%ARGS>

<%METHOD Content>

<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$Name => undef
$CFHintId => undef
</%ARGS>
<%perl>
$m->comp(
$EditComponent,
Expand Down Expand Up @@ -79,21 +163,15 @@ if ( $error_msg ) {
<% $CustomField->FriendlyPattern %>
</span>
% }
% $m->callback( CallbackName => 'AfterCustomFieldValue', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );
</&>
% $m->callback( CallbackName => 'AfterCustomFieldValue', CallbackPage => '/Elements/EditCustomField', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );

<%INIT>

my $Type = $CustomField->Type;
unless ( $Type ) {
# if we can't see the type, all hell will break loose.
$RT::Logger->error( "Custom field #". $CustomField->id ." has empty type" );
return;
}

my $Values;

if ( $Object ) {
$Grouping =~ s/\W//g if $Grouping;

if ( $Object->Id ) {
$Values = $Object->CustomFieldValues( $CustomField->id );
Expand All @@ -107,37 +185,6 @@ if ( $Object ) {
}
}

my $Name;
if ( !$NamePrefix ) {
$Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
}

my $CFHintId;
my $cf_name_prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );

if ($ShowHints and $CustomField->FriendlyPattern) {
$CFHintId = $cf_name_prefix . 'Hint';
}

# Always fill $Default with submited values if it's empty
if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
my %TOP = %$DECODED_ARGS;
$Default = $TOP{ $Name } if $Name;
# check both -Values and -Value for back compatibility
if ( $NamePrefix ) {
$Default //= $TOP{ $NamePrefix . $CustomField->Id . '-Values' }
// $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
}
else {
$Default //= $TOP{ $cf_name_prefix . 'Values' } // $TOP{ $cf_name_prefix . 'Value' };
}
}

if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
$Default = $CustomField->DefaultValues(Object => $on || RT->System);
}

my $MaxValues = $CustomField->MaxValues;
if ($MaxValues == 1 && $Values) {
# what exactly is this doing? Without the "unless" it breaks RTFM
Expand Down Expand Up @@ -183,27 +230,7 @@ if ( $m->notes('InvalidField-' . $CustomField->Id . ($Grouping ? "-$Grouping" :
}

my $EditComponent = "EditCustomField$Type";
$m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$m->callback( %ARGS, CallbackName => 'EditComponentName', CallbackPage => '/Elements/EditCustomField', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$EditComponent = "EditCustomField$Type" unless $m->comp_exists($EditComponent);

my $FormText;

if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

</%INIT>
<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$Label => undef
</%ARGS>
</%METHOD>

0 comments on commit c61d33b

Please sign in to comment.