Skip to content

Commit

Permalink
Merge pull request #2402 from RotherOSS/issue-#issue-#2290-referenz_l…
Browse files Browse the repository at this point in the history
…ens_take2

Issue #2290: saner set up of the list of referenced object type
  • Loading branch information
bschmalhofer authored Jul 17, 2023
2 parents 2a68b2a + 8fb09f1 commit 55e0119
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
15 changes: 9 additions & 6 deletions Kernel/Config/Files/XML/DynamicFields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -990,15 +990,18 @@
<Item Key="DisplayName" Translatable="1">Reference</Item>
<Item Key="Module">Kernel::System::DynamicField::Driver::Reference</Item>
<Item Key="ConfigDialog">AdminDynamicFieldReference</Item>
<Item Key="ReferencedObjectTypes">
<Array>
<Item>Ticket</Item>
<Item>ITSMConfigItem</Item>
</Array>
</Item>
</Hash>
</Value>
</Setting>
<Setting Name="DynamicFields::Driver###Reference###ReferencedObjectTypes###002-Ticket" Required="0" Valid="1">
<Description Translatable="1">Referenced object types that are related to tickets and articles.</Description>
<Navigation>Core::DynamicFields::DriverRegistration</Navigation>
<Value>
<Array>
<Item>Ticket</Item>
</Array>
</Value>
</Setting>
<Setting Name="Loader::Agent::CommonJS###200-DynamicFieldReference" Required="1" Valid="1">
<Description Translatable="1">List of JS files to always be loaded for the agent interface.</Description>
<Navigation>Frontend::Base::Loader</Navigation>
Expand Down
27 changes: 16 additions & 11 deletions Kernel/Modules/AdminDynamicField.pm
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,20 @@ 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} ) {
for my $ReferencedObjectType ( $FieldTypeConfig->{Reference}->{ReferencedObjectTypes}->@* ) {
push @FieldList,
{
Key => join( '::', 'Reference', $ReferencedObjectType ),
Value => join( '::', 'Reference', $ReferencedObjectType ),
},
;
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 ),
};
}
}
}

Expand All @@ -242,9 +246,10 @@ sub _ShowOverview {
);

# This is a workaround for Reference dynamic fields.
# Inject additional date in the option.
$AddDynamicFieldStrg =~ s[(?=>\s*ITSMConfigItem</option>)][ data-referenced_object_type="ITSMConfigItem"];
$AddDynamicFieldStrg =~ s[(?=>\s*Ticket</option>)][ data-referenced_object_type="Ticket"];
# 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;

my $ObjectTypeName = $Kernel::OM->Get('Kernel::Config')->Get('DynamicFields::ObjectType')
->{$ObjectType}->{DisplayName} || $ObjectType;
Expand Down

0 comments on commit 55e0119

Please sign in to comment.