Merge branch '2.4' into 2

This commit is contained in:
Maxime Rainville 2020-10-22 13:41:47 +13:00
commit ccca22c6fa
2 changed files with 33 additions and 2 deletions

View File

@ -6,7 +6,6 @@ use Exception;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\MultiSelectField;
use SilverStripe\Forms\Validator;
@ -321,7 +320,15 @@ class TagField extends MultiSelectField
return parent::setValue($value);
}
return parent::setValue(array_filter($value));
// Safely map php / react-select values to flat list
$values = [];
foreach ($value as $item) {
if ($item) {
$values[] = isset($item['Value']) ? $item['Value'] : $item;
}
}
return parent::setValue($values);
}
/**

View File

@ -131,6 +131,30 @@ class TagFieldTest extends SapphireTest
$record
);
}
public function testSavesReactTags()
{
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
$record->write();
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
$field->setValue([
[
'Title' => 'Tag1',
'Value' => 'Tag1',
],
[
'Title' => 'Tag2',
'Value' => 'Tag2',
],
]);
$field->saveInto($record);
$this->compareExpectedAndActualTags(
['Tag1', 'Tag2'],
$record
);
}
/**
* Ensure that {@see TagField::saveInto} respects existing tags