From bf78198fd8063d34825a35dd8f833f1cb3c86fb3 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 20 Dec 2024 16:01:13 -0500 Subject: [PATCH] make sure we always get an array --- modules/backend/formwidgets/TagList.php | 14 ++++++-------- .../formwidgets/taglist/partials/_taglist.php | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/backend/formwidgets/TagList.php b/modules/backend/formwidgets/TagList.php index 9773cb3d7d..d718e0b3bc 100644 --- a/modules/backend/formwidgets/TagList.php +++ b/modules/backend/formwidgets/TagList.php @@ -110,15 +110,17 @@ public function prepareVars() */ public function getSaveValue($value) { - if (is_array($value)) { - $value = array_filter($value); + if (!is_array($value)) { + $value = [$value]; } + $value = array_filter($value); + if ($this->mode === static::MODE_RELATION) { return $this->hydrateRelationSaveValue($value); } - if (is_array($value) && $this->mode === static::MODE_STRING) { + if ($this->mode === static::MODE_STRING) { return implode($this->getSeparatorCharacter(), $value); } @@ -129,12 +131,8 @@ public function getSaveValue($value) * Returns an array suitable for saving against a relation (array of keys). * This method also creates non-existent tags. */ - protected function hydrateRelationSaveValue($names): ?array + protected function hydrateRelationSaveValue(array $names): ?array { - if (!is_array($names)) { - $names = [$names]; - } - $relation = $this->getRelationObject(); $relationModel = $this->getRelationModel(); diff --git a/modules/backend/formwidgets/taglist/partials/_taglist.php b/modules/backend/formwidgets/taglist/partials/_taglist.php index d9d0991aef..a4170908ed 100644 --- a/modules/backend/formwidgets/taglist/partials/_taglist.php +++ b/modules/backend/formwidgets/taglist/partials/_taglist.php @@ -29,7 +29,7 @@