From fd83c0772d7607b31714232b00ac4f0ff7face54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Wed, 22 Nov 2023 12:14:56 +0100 Subject: [PATCH] Issue #2637: Adjusted admin dynamic field overview and reference module. --- Kernel/Modules/AdminDynamicField.pm | 40 ++++++++------------ Kernel/Modules/AdminDynamicFieldReference.pm | 13 +++++-- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/Kernel/Modules/AdminDynamicField.pm b/Kernel/Modules/AdminDynamicField.pm index b32b34a40b..79f0868889 100644 --- a/Kernel/Modules/AdminDynamicField.pm +++ b/Kernel/Modules/AdminDynamicField.pm @@ -200,12 +200,21 @@ sub _ShowOverview { my $SelectName = $ObjectType . 'DynamicField'; - my @FieldList = map { - { - Key => $_, - Value => $FieldTypes{$_} + my @FieldList; + FIELDTYPE: + for my $FieldTypeName ( sort { $FieldDialogs{$a} cmp $FieldDialogs{$b} } keys %FieldTypes ) { + + # group reference field types to show in tree view + my $Value = $FieldTypes{$FieldTypeName}; + if ( $FieldDialogs{$FieldTypeName} =~ /^AdminDynamicFieldReference$/ ) { + $Value = 'Reference::' . $Value; } - } sort grep { $_ ne 'Reference' } keys %FieldTypes; + + push @FieldList, { + Key => $FieldTypeName, + Value => $Value, + }; + } for my $Field (@FieldList) { @@ -214,25 +223,6 @@ sub _ShowOverview { } } - # This is a workaround for Reference dynamic fields. - # We want a entry for each of the possible referenced object types. - # E.g. Ticket, ITSMConfigItem, ITSMConfigItemVersion. - # The list of referenced object types may come from several XML-files, - # therefore we assemble the complete list from several smaller lists. - # Sorting is handled by TreeView. - # The Key must be unique as otherwise the JS handler becomes confused. - if ( $FieldTypes{Reference} && $FieldTypeConfig->{Reference}->{ReferencedObjectTypes} ) { - for my $Types ( values $FieldTypeConfig->{Reference}->{ReferencedObjectTypes}->%* ) { - for my $Type ( $Types->@* ) { - push @FieldList, - { - Key => join( '::', 'Reference', $Type ), - Value => join( '::', 'Reference', $Type ), - }; - } - } - } - # create the Add Dynamic Field select my $AddDynamicFieldStrg = $LayoutObject->BuildSelection( Data => \@FieldList, @@ -249,7 +239,7 @@ sub _ShowOverview { # Inject additional data into the option tag. # E.g. # See https://www.w3schools.com/tags/att_data-.asp - $AddDynamicFieldStrg =~ s[ (value="Reference::(\w+)")>][ $1 data-referenced_object_type="$2">]g; + $AddDynamicFieldStrg =~ s[ (value="(\w+)Reference")>][ $1 data-referenced_object_type="$2">]g; my $ObjectTypeName = $Kernel::OM->Get('Kernel::Config')->Get('DynamicFields::ObjectType') ->{$ObjectType}->{DisplayName} || $ObjectType; diff --git a/Kernel/Modules/AdminDynamicFieldReference.pm b/Kernel/Modules/AdminDynamicFieldReference.pm index c4e7d00689..f89e2d453d 100644 --- a/Kernel/Modules/AdminDynamicFieldReference.pm +++ b/Kernel/Modules/AdminDynamicFieldReference.pm @@ -54,6 +54,7 @@ sub Run { ); my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout'); + my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request'); # Get the field specific setting during the runtime as the # complete list depends on the previous selection of ReferencedObjectType. @@ -61,10 +62,14 @@ sub Run { # TODO: add GetFieldTypeSettings() to the backend object my @FieldTypeSettings; { - my $DriverObject = $Kernel::OM->Get('Kernel::System::DynamicField::Driver::Reference'); - @FieldTypeSettings = $DriverObject->GetFieldTypeSettings( - ParamObject => $Kernel::OM->Get('Kernel::System::Web::Request'), - ); + my $FieldType = $ParamObject->GetParam( Param => 'FieldType' ); + + if ($FieldType) { + my $DriverObject = $Kernel::OM->Get( 'Kernel::System::DynamicField::Driver::' . $FieldType ); + @FieldTypeSettings = $DriverObject->GetFieldTypeSettings( + ParamObject => $ParamObject, + ); + } } if ( $Self->{Subaction} eq 'Add' ) {