Skip to content

Commit 2a56ec6

Browse files
authored
Merge pull request #684 from cosmocode/clear-multi-media
Clear multi field of type media
2 parents 1ad6d6f + 6605560 commit 2a56ec6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

_test/ValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use dokuwiki\plugin\struct\test\mock\Assignments;
77
use dokuwiki\plugin\struct\test\mock\Lookup;
88
use dokuwiki\plugin\struct\types\Decimal;
9+
use dokuwiki\plugin\struct\types\Media;
910
use dokuwiki\plugin\struct\types\Text;
1011

1112
/**
@@ -105,6 +106,17 @@ public function test_validate_empty_multivalue()
105106

106107
$validator->validateValue($col, $value);
107108
$this->assertEquals([''], $value);
109+
110+
// some fields like media or date can post an array with multiple empty strings
111+
// because they use multiple inputs instead of comma separation in one input
112+
$media = new Media(null, '', true);
113+
$col = new Column(10, $media);
114+
115+
$validator = new mock\ValueValidator();
116+
$value = ['', '', ''];
117+
118+
$validator->validateValue($col, $value);
119+
$this->assertEquals([''], $value);
108120
}
109121

110122
}

meta/ValueValidator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ public function validateValue(Column $col, &$rawvalue)
4242
}
4343
// strip empty fields from multi vals
4444
// but keep at least one so we can properly delete multivalues on update
45-
if (is_array($rawvalue) && count($rawvalue) > 1) {
45+
// some fields like media or date can post an array with multiple empty strings
46+
// because they use multiple inputs instead of comma separation in one input
47+
if (is_array($rawvalue)) {
4648
$rawvalue = array_filter($rawvalue, [$this, 'filter']);
4749
$rawvalue = array_values($rawvalue); // reset the array keys
50+
if (empty($rawvalue)) {
51+
$rawvalue = [''];
52+
}
4853
}
4954

5055
// validate data

0 commit comments

Comments
 (0)