mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
support multiple values in CertificateField
This commit is contained in:
parent
6c79ec958b
commit
f7ceeb3eff
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user