From def4a030c8823e1cf3ebbe9291b532223a20e9d2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 11 Jun 2014 13:33:57 +0200 Subject: [PATCH] =?utf8?q?CVars:=20beim=20Autovivifien=20g=C3=BCltigen=20W?= =?utf8?q?ert=20f=C3=BCr=20selects=20for=C3=A7ieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/CustomVariableConfig.pm | 9 +++++++++ SL/DB/Helper/CustomVariables.pm | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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; } -- 2.20.1