mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-06-14 08:49:07 +02:00
Merge pull request #233 from w-huber/2
add performReadonlyTransformation
This commit is contained in:
commit
1b9f5a9388
|
@ -412,4 +412,11 @@ class StringTagField extends DropdownField
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function performReadonlyTransformation()
|
||||||
|
{
|
||||||
|
$field = parent::performReadonlyTransformation();
|
||||||
|
$field->setValue(implode(', ', $this->Value()));
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,22 +171,26 @@ class StringTagFieldTest extends SapphireTest
|
||||||
$this->assertNotEmpty($attributes['data-schema']);
|
$this->assertNotEmpty($attributes['data-schema']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testPerformReadonlyTransformation()
|
||||||
* Ensure a source of tags matches the given string tag names
|
|
||||||
*
|
|
||||||
* @param array $expected
|
|
||||||
* @param DataList $actualSource
|
|
||||||
*/
|
|
||||||
protected function compareTagLists(array $expected, DataList $actualSource)
|
|
||||||
{
|
{
|
||||||
$actual = array_keys($actualSource->map('ID', 'Title')->toArray());
|
$field = new StringTagField('Tags');
|
||||||
sort($expected);
|
$field->setSource(['Test1', 'Test2', 'Test3']);
|
||||||
sort($actual);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
// Ensure a single value can be rendered
|
||||||
$expected,
|
$field->setValue(['Test2']);
|
||||||
$actual
|
$field_readonly = $field->performReadonlyTransformation();
|
||||||
);
|
$this->assertEquals('Test2', $field_readonly->Value());
|
||||||
|
|
||||||
|
// Ensure multiple valid values are rendered
|
||||||
|
$field->setValue(['Test1', 'Test2']);
|
||||||
|
$field_readonly = $field->performReadonlyTransformation();
|
||||||
|
$this->assertEquals('Test1, Test2', $field_readonly->Value());
|
||||||
|
|
||||||
|
// Ensure an value not in the source array is still rendered
|
||||||
|
// (because e.g. in history view it must have been a valid value when it was set)
|
||||||
|
$field->setValue(['Test', 'Test1']);
|
||||||
|
$field_readonly = $field->performReadonlyTransformation();
|
||||||
|
$this->assertEquals('Test, Test1', $field_readonly->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user