Skip to content

Commit

Permalink
Issue #2987: Add and update field config param 'PartOfSet' for set-in…
Browse files Browse the repository at this point in the history
…cluded fields.
  • Loading branch information
stefanhaerter committed Feb 26, 2024
1 parent 1ecd8e9 commit 1bd742b
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Kernel/Modules/AdminDynamicFieldSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use warnings;

our $ObjectManagerDisabled = 1;

use List::Util qw(any);

use Kernel::System::VariableCheck qw(:all);
use Kernel::Language qw(Translatable);

Expand Down Expand Up @@ -391,6 +393,34 @@ sub _AddAction {
);
}

# collect list of included fields
my @FieldList;
for my $IncludedElement (@Include) {
if ( $IncludedElement->{DF} ) {
push @FieldList, $IncludedElement->{DF};
}
elsif ( $IncludedElement->{Grid} ) {
for my $Row ( $IncludedElement->{Grid}{Rows}->@* ) {
push @FieldList, $Row->{DF};
}
}
}

# update configs of included fields
for my $IncludedField (@FieldList) {
my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
Name => $IncludedField,
);
$DynamicFieldObject->DynamicFieldUpdate(
$DynamicFieldConfig->%*,
Config => {
$DynamicFieldConfig->{Config}->%*,
PartOfSet => 1,
},
UserID => $Self->{UserID},
);
}

# set specific config
my $FieldConfig = {
Tooltip => $GetParam{Tooltip},
Expand Down Expand Up @@ -693,6 +723,54 @@ sub _ChangeAction {
);
}

# collect list of currently included fields
my @NewFieldList;
for my $IncludedElement (@Include) {
if ( $IncludedElement->{DF} ) {
push @NewFieldList, $IncludedElement->{DF};
}
elsif ( $IncludedElement->{Grid} ) {
for my $Row ( $IncludedElement->{Grid}{Rows}->@* ) {
push @NewFieldList, $Row->{DF};
}
}
}

# collect list of previous included fields
my @OldFieldList;
for my $IncludedElement ( $DynamicFieldData->{Config}{Include}->@* ) {
if ( $IncludedElement->{DF} ) {
push @OldFieldList, $IncludedElement->{DF};
}
elsif ( $IncludedElement->{Grid} ) {
for my $Row ( $IncludedElement->{Grid}{Rows}->@* ) {
push @OldFieldList, $Row->{DF};
}
}
}

# update configs of included fields
FIELD:
for my $IncludedField ( @NewFieldList, @OldFieldList ) {

my $PartOfSet = ( any { $_ eq $IncludedField } @NewFieldList ) || 0;

# skip field if nothing changed
next FIELD if $PartOfSet && grep { $_ eq $IncludedField } @OldFieldList;

my $DynamicFieldConfig = $DynamicFieldObject->DynamicFieldGet(
Name => $IncludedField,
);
$DynamicFieldObject->DynamicFieldUpdate(
$DynamicFieldConfig->%*,
Config => {
$DynamicFieldConfig->{Config}->%*,
PartOfSet => $PartOfSet,
},
UserID => $Self->{UserID},
);
}

# set specific config
my $FieldConfig = {
Tooltip => $GetParam{Tooltip},
Expand Down

0 comments on commit 1bd742b

Please sign in to comment.