Commit a6df7a3b authored by Frank Wall's avatar Frank Wall Committed by Franco Fichtner

support multiple values in CertificateField

(cherry picked from commit f7ceeb3e)
parent 67da992b
......@@ -29,7 +29,7 @@
*/
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
use OPNsense\Core\Config;
/**
......@@ -49,6 +49,11 @@ class CertificateField extends BaseField
*/
private $certificateType = "cert";
/**
* @var bool field may contain multiple certs at once
*/
private $internalMultiSelect = false;
/**
* @var string default validation message string
*/
......@@ -59,7 +64,6 @@ class CertificateField extends BaseField
*/
private static $internalOptionList = array();
/**
* set certificate type (cert/ca)
* @param $value certificate type
......@@ -73,6 +77,19 @@ class CertificateField extends BaseField
}
}
/**
* select if multiple certs 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;
}
}
/**
* generate validation data (list of certificates)
*/
......@@ -97,8 +114,10 @@ class CertificateField extends BaseField
if (!$this->internalIsRequired) {
$result[""] = array("value" => gettext("none"), "selected" => 0);
}
$certs = explode(',', $this->internalValue);
foreach (self::$internalOptionList as $optKey => $optValue) {
if ($optKey == $this->internalValue) {
if (in_array($optKey, $certs)) {
$selected = 1;
} else {
$selected = 0;
......@@ -117,7 +136,7 @@ class CertificateField extends BaseField
{
$validators = parent::getValidators();
if ($this->internalValue != null) {
$validators[] = new InclusionIn(array('message' => $this->internalValidationMessage,
$validators[] = new CsvListValidator(array('message' => $this->internalValidationMessage,
'domain'=>array_keys(self::$internalOptionList)));
}
return $validators;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment