model, extend NetworkField so multiple items can be returned as a list (like other options), for https://github.com/opnsense/core/issues/1793

This commit is contained in:
Ad Schellevis 2017-08-29 21:08:12 +02:00
parent 060b794685
commit 5d457fed10

View File

@ -62,6 +62,11 @@ class NetworkField extends BaseField
*/
protected $internalWildcardEnabled = true;
/**
* @var bool when set, results are returned as list (with all options enabled)
*/
private $internalAsList = false;
/**
* always lowercase / trim networks
* @param string $value
@ -106,6 +111,38 @@ class NetworkField extends BaseField
}
}
/**
* select if multiple networks may be selected at once
* @param $value boolean value 0/1
*/
public function setAsList($value)
{
if (trim(strtoupper($value)) == "Y") {
$this->internalAsList = true;
} else {
$this->internalAsList = false;
}
}
/**
* get valid options, descriptions and selected value
* @return array
*/
public function getNodeData()
{
if ($this->internalAsList) {
// return result as list
$result = array();
foreach (explode(',', $this->internalValue) as $net) {
$result[$net] = array("value" => $net, "selected" => 1);
}
return $result;
} else {
// normal, single field response
return $this->internalValue;
}
}
/**
* retrieve field validators for this field type
* @return array returns Text/regex validator