mirror of
https://github.com/cosmocode/dokuwiki-plugin-struct.git
synced 2025-07-29 11:59:24 +00:00
Merge pull request #684 from cosmocode/clear-multi-media
Clear multi field of type media
This commit is contained in:
@ -6,6 +6,7 @@ use dokuwiki\plugin\struct\meta\Column;
|
||||
use dokuwiki\plugin\struct\test\mock\Assignments;
|
||||
use dokuwiki\plugin\struct\test\mock\Lookup;
|
||||
use dokuwiki\plugin\struct\types\Decimal;
|
||||
use dokuwiki\plugin\struct\types\Media;
|
||||
use dokuwiki\plugin\struct\types\Text;
|
||||
|
||||
/**
|
||||
@ -105,6 +106,17 @@ class ValidatorTest extends StructTest
|
||||
|
||||
$validator->validateValue($col, $value);
|
||||
$this->assertEquals([''], $value);
|
||||
|
||||
// some fields like media or date can post an array with multiple empty strings
|
||||
// because they use multiple inputs instead of comma separation in one input
|
||||
$media = new Media(null, '', true);
|
||||
$col = new Column(10, $media);
|
||||
|
||||
$validator = new mock\ValueValidator();
|
||||
$value = ['', '', ''];
|
||||
|
||||
$validator->validateValue($col, $value);
|
||||
$this->assertEquals([''], $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,9 +42,14 @@ class ValueValidator
|
||||
}
|
||||
// strip empty fields from multi vals
|
||||
// but keep at least one so we can properly delete multivalues on update
|
||||
if (is_array($rawvalue) && count($rawvalue) > 1) {
|
||||
// some fields like media or date can post an array with multiple empty strings
|
||||
// because they use multiple inputs instead of comma separation in one input
|
||||
if (is_array($rawvalue)) {
|
||||
$rawvalue = array_filter($rawvalue, [$this, 'filter']);
|
||||
$rawvalue = array_values($rawvalue); // reset the array keys
|
||||
if (empty($rawvalue)) {
|
||||
$rawvalue = [''];
|
||||
}
|
||||
}
|
||||
|
||||
// validate data
|
||||
|
Reference in New Issue
Block a user