Skip to content

Commit

Permalink
Issue #2251: Adjusted dynamic field drivers to pass on readonly attri…
Browse files Browse the repository at this point in the history
…bute.
  • Loading branch information
stefanhaerter committed Nov 21, 2023
1 parent 8431eef commit d2c6428
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/BaseDatabase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

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

# delete the template value
pop @Data;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/BaseDateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my %Data;

# retrieve value parts as arrays
Expand Down
7 changes: 3 additions & 4 deletions Kernel/System/DynamicField/Driver/BaseEntity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ sub EditFieldRender {
my $FieldID = $FieldName . '_' . $ValueIndex;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand All @@ -283,7 +283,7 @@ sub EditFieldRender {
my @SelectedIDs = grep {$_} $Value->@*;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
SelectedID => \@SelectedIDs,
Class => $FieldClass,
Expand Down Expand Up @@ -332,7 +332,6 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Name => $FieldName,
ID => $FieldTemplateData{FieldID},
Translation => $FieldConfig->{TranslatableValues} || 0,
Expand Down Expand Up @@ -415,7 +414,7 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

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

# delete the template value
pop @Data;
Expand Down
4 changes: 3 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseScript.pm
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ sub EditFieldValueGet {
)
{
$Value = $Param{ParamObject}->GetParam( Param => $FieldName );
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {

# TODO check what happens with template data
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my @DataAll = $Param{ParamObject}->GetArray( Param => $FieldName );
my @Data;

Expand Down
6 changes: 4 additions & 2 deletions Kernel/System/DynamicField/Driver/BaseSelect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $DataValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand Down Expand Up @@ -470,7 +470,9 @@ sub EditFieldValueGet {
my @Data;

# delete the template value
pop @DataAll;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @DataAll;
}

for my $Item (@DataAll) {
push @Data, $Item // '';
Expand Down
4 changes: 3 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseText.pm
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ sub EditFieldValueGet {
my @Data;

# delete the template value
pop @DataAll;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @DataAll;
}

# delete empty values (can happen if the user has selected the "-" entry)
for my $Item (@DataAll) {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/Checkbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my @DataValues = $Param{ParamObject}->GetArray( Param => $FieldName );
my @DataUsed = $Param{ParamObject}->GetArray( Param => $FieldName . 'Used' );

Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my %Data;

# retrieve value parts as arrays
Expand Down
1 change: 1 addition & 0 deletions Kernel/System/DynamicField/Driver/Multiselect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ sub EditFieldRender {
Class => $FieldClass,
HTMLQuote => 1,
Multiple => 1,
Readonly => $Param{Readonly},
);

my %FieldTemplateData = (
Expand Down
42 changes: 39 additions & 3 deletions Kernel/System/DynamicField/Driver/Reference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ sub EditFieldRender {
my $FieldID = $FieldName . '_' . $ValueIndex;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand All @@ -339,7 +339,7 @@ sub EditFieldRender {
my @SelectedIDs = grep {$_} $Value->@*;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
SelectedID => \@SelectedIDs,
Class => $FieldClass,
Expand Down Expand Up @@ -410,7 +410,6 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Name => $FieldName,
ID => $FieldTemplateData{FieldID},
Class => $FieldClass,
Expand Down Expand Up @@ -480,6 +479,43 @@ sub EditFieldValueGet {

# get the value from the parent class
my $Value = $Self->SUPER::EditFieldValueGet(%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
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
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,
};
}
>>>>>>> e480c1fbd (Issue #2251: Adjusted dynamic field drivers to pass on readonly attribute.)

# for this field the normal return an the ReturnValueStructure are the same
return $Value unless $Param{ForLens};
Expand Down
8 changes: 5 additions & 3 deletions Kernel/System/DynamicField/Driver/WebService.pm
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $DataValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand Down Expand Up @@ -403,10 +403,12 @@ 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;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @Data;
}
$Value = \@Data;

}
Expand Down

0 comments on commit d2c6428

Please sign in to comment.