Skip to content

Commit

Permalink
Issue #2648: DF Reference now uses ValueSet and EditFieldValueGet met…
Browse files Browse the repository at this point in the history
…hods of parent class.

Logic in BaseEntity driver adapted to the needs of df reference.
  • Loading branch information
stefanhaerter committed Nov 7, 2023
1 parent fe023ee commit 424d7f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 59 deletions.
8 changes: 7 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseEntity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,17 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {

# delete the template value
pop @Data;
}
else {

# delete empty values
@Data = grep {$_} @Data;
}

$Value = \@Data;
}

Expand Down
61 changes: 3 additions & 58 deletions Kernel/System/DynamicField/Driver/Reference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,6 @@ sub ValueGet {
return $Value;
}

sub ValueSet {
my ( $Self, %Param ) = @_;

my $DBValue = $Self->ValueStructureToDB(
Value => $Param{Value},
ValueKey => $Self->{ValueKey},
Set => $Param{Set},
MultiValue => $Param{DynamicFieldConfig}{Config}{MultiValue},
);

return $Kernel::OM->Get('Kernel::System::DynamicFieldValue')->ValueSet(
FieldID => $Param{DynamicFieldConfig}->{ID},
ObjectID => $Param{ObjectID},
Value => $DBValue,
UserID => $Param{UserID},
);
}

sub ValueValidate {
my ( $Self, %Param ) = @_;

Expand Down Expand Up @@ -280,12 +262,7 @@ sub EditFieldRender {
);

# set values from ParamObject if present
if ( $DFDetails->{MultiValue} ) {
if ( $FieldValue->@* ) {
$Value = $FieldValue;
}
}
elsif ( defined $FieldValue ) {
if ( defined $FieldValue && $FieldValue && $FieldValue->@* ) {
$Value = $FieldValue;
}

Expand Down Expand Up @@ -501,40 +478,8 @@ EOF
sub EditFieldValueGet {
my ( $Self, %Param ) = @_;

my $FieldName = 'DynamicField_' . $Param{DynamicFieldConfig}->{Name};

my $Value;

# check if there is a Template and retrieve the dynamic field value from there
if ( IsHashRefWithData( $Param{Template} ) && defined $Param{Template}->{$FieldName} ) {
$Value = $Param{Template}->{$FieldName};
}

# otherwise get dynamic field value from the web request
elsif (
defined $Param{ParamObject}
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
my @DataAll = $Param{ParamObject}->GetArray( Param => $FieldName );

# delete the template value
pop @DataAll;

# delete empty values (can happen if the user has selected the "-" entry)
$Value = [ map { $_ // '' } @DataAll ];
}
else {
$Value = $Param{ParamObject}->GetParam( Param => $FieldName );
}
}

if ( defined $Param{ReturnTemplateStructure} && $Param{ReturnTemplateStructure} eq '1' ) {
return {
$FieldName => $Value,
};
}
# get the value from the parent class
my $Value = $Self->SUPER::EditFieldValueGet(%Param);

# for this field the normal return an the ReturnValueStructure are the same
return $Value unless $Param{ForLens};
Expand Down

0 comments on commit 424d7f3

Please sign in to comment.