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.
This commit is contained in:
Sam Minnee 2020-06-17 16:40:57 +12:00
parent 3b6ec92e66
commit d11b9474ed
2 changed files with 8 additions and 0 deletions

View File

@ -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;
}

View File

@ -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()