Fix MultiSelect when empty selection is given

This commit is contained in:
Martin Rüegg 2023-12-20 10:36:11 +01:00
parent e1069cac6c
commit 8f965a2844
No known key found for this signature in database
4 changed files with 17 additions and 6 deletions

View File

@ -1,7 +1,11 @@
HumHub Changelog
================
1.15.2 (December 19, 2023)
1.15.3 (unreleased)
--------------------------
- Fix #6768 MultiSelect when empty selection is given
- 1.15.2 (December 19, 2023)
--------------------------
- Fix #6753: Non-unique key used for permission caching
- Fix #6741: Fix no pretty url of password recovery link

View File

@ -4,6 +4,12 @@ Module Migration Guide
See [humhub/documentation::docs/develop/modules-migrate.md](https://github.com/humhub/documentation/blob/master/docs/develop/modules-migrate.md)
for full version.
Version 1.15.3
-------------------------
### Bugfix with potential side-effect
- `\humhub\modules\ui\form\widgets\BasePicker` and `\humhub\modules\ui\form\widgets\MultiSelect` do now treat and empty array for the field `BasePicker::$selection` as a valid selection list and will not attempt to get the list from the model in that case.
Version 1.15
-------------------------

View File

@ -238,7 +238,7 @@ abstract class BasePicker extends JsInputWidget
*/
public function run()
{
if ($this->selection != null && !is_array($this->selection)) {
if ($this->selection !== null && !is_array($this->selection)) {
$this->selection = [$this->selection];
}
@ -280,7 +280,7 @@ abstract class BasePicker extends JsInputWidget
*/
protected function getSelectedOptions()
{
if (!$this->selection && $this->model != null) {
if ($this->selection === null && $this->model !== null) {
$attribute = $this->attribute;
if (strrpos($attribute, '[') !== false) {
$this->selection = $this->loadItems(Html::getAttributeValue($this->model, $attribute));
@ -289,7 +289,6 @@ abstract class BasePicker extends JsInputWidget
}
}
if (!$this->selection) {
$this->selection = [];
}

View File

@ -8,6 +8,8 @@
namespace humhub\modules\ui\form\widgets;
use yii\helpers\ArrayHelper;
/**
* Multiselect
*
@ -51,7 +53,7 @@ class MultiSelect extends BasePicker
protected function getSelectedOptions()
{
if (empty($this->selection)) {
if ($this->selection === null) {
$attribute = $this->attribute;
$this->selection = ($this->model) ? $this->model->$attribute : [];
}
@ -66,7 +68,7 @@ class MultiSelect extends BasePicker
continue;
}
$result[$key] = $this->buildItemOption([$key => $value], in_array($key, $this->selection));
$result[$key] = $this->buildItemOption([$key => $value], ArrayHelper::keyExists($key, $this->selection));
}
return $result;
}