From f96afca6415d885e41046cb4105fb3e2a47a4f1a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 2 Nov 2020 15:20:48 +0100 Subject: [PATCH] wip #4031 @0:20 --- src/app/Magic/Fields/SelectFromArray.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/Magic/Fields/SelectFromArray.php b/src/app/Magic/Fields/SelectFromArray.php index e313bfa..c9d00e5 100644 --- a/src/app/Magic/Fields/SelectFromArray.php +++ b/src/app/Magic/Fields/SelectFromArray.php @@ -16,16 +16,28 @@ class SelectFromArray extends Field protected $_multiple = false; protected $_allowNull = true; protected $_options = []; + protected $_options_aliases = []; public function getDefaultAttributes() { - return array_merge(parent::getDefaultAttributes(), ['options' => $this->_options, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple]); + return array_merge(parent::getDefaultAttributes(), ['options' => $this->_options, 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple]); } + public function getColumnData() { $res = parent::getColumnData(); $res['options'] = $this->getAttribute('options'); return $res; } + + public function filterValue($value) + { + $value = parent::filterValue($value); + $aliases = $this->getAttribute('options_aliases', []); + if (isset($aliases[$value])) { + $value = $aliases[$value]; + } + return $value; + } } -- 2.39.5