Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty item for all taglist modes #1276

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ public function prepareVars()
*/
public function getSaveValue($value)
{
if (!is_array($value)) {
$value = [$value];
}
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved

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

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
Loading