mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX / TreeMultiselectField::objectForKey handles list of IDs correctly
This commit is contained in:
parent
80885fc231
commit
9ce6d91b76
@ -279,10 +279,14 @@ class TreeMultiselectField extends TreeDropdownField
|
||||
* of numeric types with string values, issuing a database error.
|
||||
*
|
||||
* This fix is not ideal, but supposed to keep backward compatibility for SS4.
|
||||
* Since SS5 this method should be removed and NULL should be used instead of 'unchanged'.
|
||||
*
|
||||
* In 5.0 this method to be removed and NULL should be used instead of 'unchanged' (or an empty array. to be decided).
|
||||
* In 5.0 this class to be refactored so that $this->value is always an array of values (or null)
|
||||
*/
|
||||
if ($this->getKeyField() === 'ID' && $key === 'unchanged') {
|
||||
$key = null;
|
||||
} elseif (is_string($key)) {
|
||||
$key = preg_split('/\s*,\s*/', trim($key));
|
||||
}
|
||||
|
||||
return parent::objectForKey($key);
|
||||
|
@ -20,6 +20,9 @@ class TreeMultiselectFieldTest extends SapphireTest
|
||||
$schemaStateDefaults = $field->getSchemaStateDefaults();
|
||||
$this->assertArraySubset(['id' => 'TestTree', 'name' => 'TestTree', 'value' => 'unchanged'], $schemaStateDefaults, $strict = true);
|
||||
|
||||
$items = $field->getItems();
|
||||
$this->assertCount(0, $items, $message = 'there must be no items selected');
|
||||
|
||||
$html = $field->performReadonlyTransformation()->Field();
|
||||
|
||||
$this->assertEquals(
|
||||
@ -45,6 +48,9 @@ HTML
|
||||
$schemaStateDefaults = $field->getSchemaStateDefaults();
|
||||
$this->assertArraySubset(['id' => 'TestTree', 'name' => 'TestTree', 'value' => [$asdf->ID, $subfolderfile1->ID]], $schemaStateDefaults, $strict = true);
|
||||
|
||||
$items = $field->getItems();
|
||||
$this->assertCount(2, $items, $message = 'there must be exactly 2 items selected');
|
||||
|
||||
$html = (string)$field->performReadonlyTransformation()->Field();
|
||||
|
||||
$this->assertEquals(
|
||||
|
Loading…
Reference in New Issue
Block a user