From e1883f34ac41fcf98972135bde7e8dc3e72b1958 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 8 Nov 2019 16:04:00 +0100 Subject: [PATCH] MVC: refactor JsonKeyValueStoreField type, skip unit test since it depends on configd. for https://github.com/opnsense/core/issues/3252 --- .../FieldTypes/JsonKeyValueStoreField.php | 91 +------------------ 1 file changed, 3 insertions(+), 88 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php index 09e50e59e..04f2a2ebe 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php @@ -1,7 +1,7 @@ internalEmptyDescription = $value; - } - /** * @param string $value source field, pattern for source file */ @@ -191,19 +155,6 @@ class JsonKeyValueStoreField extends BaseField } } - /** - * select if multiple authentication servers may be selected at once - * @param $value boolean value Y/N - */ - public function setMultiple($value) - { - if (trim(strtoupper($value)) == "Y") { - $this->internalMultiSelect = true; - } else { - $this->internalMultiSelect = false; - } - } - /** * change default sorting order (value vs key) * @param $value boolean value Y/N @@ -223,49 +174,13 @@ class JsonKeyValueStoreField extends BaseField */ public function getNodeData() { - $result = array (); - // if relation is not required and single, add empty option - if (!$this->internalIsRequired && !$this->internalMultiSelect) { - $result[""] = array("value"=>$this->internalEmptyDescription, "selected" => 0); - } - - $options = explode(',', $this->internalValue); // set sorting by key (default) or value if ($this->internalSortByValue) { natcasesort($this->internalOptionList); } else { ksort($this->internalOptionList); } - foreach ($this->internalOptionList as $optKey => $optValue) { - if (in_array($optKey, $options)) { - $selected = 1; - } else { - $selected = 0; - } - $result[$optKey] = array("value"=>$optValue, "selected" => $selected); - } - return $result; + return parent::getNodeData(); } - - /** - * retrieve field validators for this field type - * @return array returns InclusionIn validator - */ - public function getValidators() - { - $validators = parent::getValidators(); - if ($this->internalValue != null) { - if ($this->internalMultiSelect) { - // field may contain more than one value - $validators[] = new CsvListValidator(array('message' => $this->internalValidationMessage, - 'domain'=>array_keys($this->internalOptionList))); - } else { - // single value selection - $validators[] = new InclusionIn(array('message' => $this->internalValidationMessage, - 'domain'=>array_keys($this->internalOptionList))); - } - } - return $validators; - } }