From 3255d4a7c04ec9d15fb62565d7bd86802f8049f3 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Thu, 2 Jan 2025 03:15:03 -0500 Subject: [PATCH] Remove empty item for all taglist modes (#1276) Fixes #1275 --- modules/backend/formwidgets/TagList.php | 16 ++++++++-------- .../formwidgets/taglist/partials/_taglist.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/backend/formwidgets/TagList.php b/modules/backend/formwidgets/TagList.php index 6b87e59a7..d718e0b3b 100644 --- a/modules/backend/formwidgets/TagList.php +++ b/modules/backend/formwidgets/TagList.php @@ -110,11 +110,17 @@ public function prepareVars() */ public function getSaveValue($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); } @@ -125,14 +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]; - } - - $names = array_filter($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 d9d0991ae..a4170908e 100644 --- a/modules/backend/formwidgets/taglist/partials/_taglist.php +++ b/modules/backend/formwidgets/taglist/partials/_taglist.php @@ -29,7 +29,7 @@