Skip to content

Commit f32c37c

Browse files
committed
Merge branch '2.11' into 2
2 parents 783ab4e + 635d13c commit f32c37c

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/StringTagField.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,11 @@ public function setCanCreate($canCreate)
416416

417417
return $this;
418418
}
419+
420+
public function performReadonlyTransformation()
421+
{
422+
$field = parent::performReadonlyTransformation();
423+
$field->setValue(implode(', ', $this->Value()));
424+
return $field;
425+
}
419426
}

tests/StringTagFieldTest.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,26 @@ public function testSchemaIsAddedToAttributes()
178178
$this->assertNotEmpty($attributes['data-schema']);
179179
}
180180

181-
/**
182-
* Ensure a source of tags matches the given string tag names
183-
*
184-
* @param array $expected
185-
* @param DataList $actualSource
186-
*/
187-
protected function compareTagLists(array $expected, DataList $actualSource)
181+
public function testPerformReadonlyTransformation()
188182
{
189-
$actual = array_keys($actualSource->map('ID', 'Title')->toArray());
190-
sort($expected);
191-
sort($actual);
192-
193-
$this->assertEquals(
194-
$expected,
195-
$actual
196-
);
183+
$field = new StringTagField('Tags');
184+
$field->setSource(['Test1', 'Test2', 'Test3']);
185+
186+
// Ensure a single value can be rendered
187+
$field->setValue(['Test2']);
188+
$field_readonly = $field->performReadonlyTransformation();
189+
$this->assertEquals('Test2', $field_readonly->Value());
190+
191+
// Ensure multiple valid values are rendered
192+
$field->setValue(['Test1', 'Test2']);
193+
$field_readonly = $field->performReadonlyTransformation();
194+
$this->assertEquals('Test1, Test2', $field_readonly->Value());
195+
196+
// Ensure an value not in the source array is still rendered
197+
// (because e.g. in history view it must have been a valid value when it was set)
198+
$field->setValue(['Test', 'Test1']);
199+
$field_readonly = $field->performReadonlyTransformation();
200+
$this->assertEquals('Test, Test1', $field_readonly->Value());
197201
}
198202

199203
/**

0 commit comments

Comments
 (0)