From d11b9474ed868710a8739099224f6979263b8d4b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 17 Jun 2020 16:40:57 +1200 Subject: [PATCH] FIX: Fix readonly transformation of field with setTitleField() If the title field was customised, this metadata was lost during a readonly transformation. This can cause fatal errors in read-only views such as history browsing. --- src/TagField.php | 2 ++ tests/TagFieldTest.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/TagField.php b/src/TagField.php index 34a5113..8235961 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -525,6 +525,8 @@ class TagField extends MultiSelectField /** @var ReadonlyTagField $copy */ $copy = $this->castedCopy(ReadonlyTagField::class); $copy->setSourceList($this->getSourceList()); + $copy->setTitleField($this->getTitleField()); + return $copy; } diff --git a/tests/TagFieldTest.php b/tests/TagFieldTest.php index 8429e4a..29e7441 100755 --- a/tests/TagFieldTest.php +++ b/tests/TagFieldTest.php @@ -352,6 +352,12 @@ class TagFieldTest extends SapphireTest $field = new TagField('Tags', '', TagFieldTestBlogTag::get()); $readOnlyField = $field->performReadonlyTransformation(); $this->assertInstanceOf(ReadonlyTagField::class, $readOnlyField); + + // Custom title field + $field = new TagField('Tags', '', TagFieldTestBlogTag::get()); + $field->setTitleField('Name'); + $readOnlyField = $field->performReadonlyTransformation(); + $this->assertEquals('Name', $readOnlyField->getTitleField()); } public function testGetSchemaDataDefaults()