Merge branch 'fix/multiselect' of github.com:metaworx/humhub into metaworx-fix/multiselect

This commit is contained in:
Lucas Bartholemy 2024-04-04 16:57:10 +02:00
commit dd2d23058d
3 changed files with 8 additions and 5 deletions

View File

@ -47,6 +47,8 @@ At least PHP 8.0 is required with this version.
- `\humhub\modules\content\models\Content` on `canEdit()`, `canView()`
- `\humhub\modules\file\models\File` on `canRead()`, `canDelete()`
### 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

@ -239,7 +239,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];
}
@ -281,7 +281,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));
@ -290,7 +290,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
*
@ -50,7 +52,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 : [];
}
@ -65,7 +67,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;
}