This commit is contained in:
Sara Arjona 2023-08-28 16:56:22 +02:00
commit a52f94b754
No known key found for this signature in database

View File

@ -29,42 +29,14 @@ class adminpresets_admin_setting_configmultiselect extends adminpresets_setting
/** @var \admin_setting_configmultiselect $settingdata */
protected $settingdata;
/**
* Ensure that the $value values are setting choices.
*
* @param mixed $value Setting value
* @return mixed Returns false if wrong param value
*/
protected function set_value($value) {
if ($value) {
$options = explode(',', $value);
foreach ($options as $option) {
foreach ($this->settingdata->choices as $key => $choice) {
if ($key == $option) {
$this->value = $option;
$this->set_visiblevalue();
return true;
}
}
}
$value = implode(',', $options);
}
$this->value = $value;
$this->set_visiblevalue();
return true;
}
protected function set_visiblevalue() {
$values = explode(',', $this->value);
$visiblevalues = [];
foreach ($values as $value) {
if (!empty($this->settingdata->choices[$value])) {
// Ensure that each value exists as a setting choice.
if (array_key_exists($value, $this->settingdata->choices)) {
$visiblevalues[] = $this->settingdata->choices[$value];
}
}