Skip to content

Commit

Permalink
Issue #2637: Adjusted admin dynamic field overview and reference module.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaerter authored and svenoe committed Nov 24, 2023
1 parent bfe2ce6 commit 80950a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
40 changes: 15 additions & 25 deletions Kernel/Modules/AdminDynamicField.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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,
Expand All @@ -249,7 +239,7 @@ sub _ShowOverview {
# Inject additional data into the option tag.
# E.g. <option value="Reference::ITSMConfigItem" data-referenced_object_type="ITSMConfigItem">&nbsp;&nbsp;ITSMConfigItem</option>
# 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;
Expand Down
13 changes: 9 additions & 4 deletions Kernel/Modules/AdminDynamicFieldReference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ 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.
# TODO: this is specifc to the dynamic field type Reference
# 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' ) {
Expand Down

0 comments on commit 80950a1

Please sign in to comment.