From: Moritz Bunkus Date: Wed, 11 Jun 2014 11:33:57 +0000 (+0200) Subject: CVars: beim Autovivifien gültigen Wert für selects forçieren X-Git-Tag: release-3.2.0beta~411^2~69 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=def4a030c8823e1cf3ebbe9291b532223a20e9d2;p=kivitendo-erp.git CVars: beim Autovivifien gültigen Wert für selects forçieren --- diff --git a/SL/DB/CustomVariableConfig.pm b/SL/DB/CustomVariableConfig.pm index 203f83a90..32b0b1c17 100644 --- a/SL/DB/CustomVariableConfig.pm +++ b/SL/DB/CustomVariableConfig.pm @@ -5,6 +5,8 @@ package SL::DB::CustomVariableConfig; use strict; +use List::MoreUtils qw(any); + use SL::DB::MetaSetup::CustomVariableConfig; use SL::DB::Manager::CustomVariableConfig; use SL::DB::Helper::ActsAsList; @@ -87,4 +89,11 @@ sub has_flag { return $self->processed_flags()->{$flag}; } +sub type_dependant_default_value { + my ($self) = @_; + + return $self->default_value if $self->type ne 'select'; + return (any { $_ eq $self->default_value } @{ $self->processed_options }) ? $self->default_value : $self->processed_options->[0]; +} + 1; diff --git a/SL/DB/Helper/CustomVariables.pm b/SL/DB/Helper/CustomVariables.pm index 737c163a9..921e70723 100644 --- a/SL/DB/Helper/CustomVariables.pm +++ b/SL/DB/Helper/CustomVariables.pm @@ -196,7 +196,7 @@ sub _new_cvar { # value needs config $inherited_value ? $cvar->value($inherited_value) - : $cvar->value($params{config}->default_value); + : $cvar->value($params{config}->type_dependant_default_value); return $cvar; }