Skip to content

Commit

Permalink
make sure we always get an array
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Dec 20, 2024
1 parent d7d1993 commit bf78198
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/formwidgets/taglist/partials/_taglist.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<?php else: ?>
<input
type="hidden"
name="<?= $field->getName() ?>"
name="<?= $field->getName() ?>[]"
value="<?= $field->value ?>">
<?php endif ?>
<?php else: ?>
Expand Down

0 comments on commit bf78198

Please sign in to comment.