Skip to content

Commit

Permalink
Merge branch '2.11' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 27, 2023
2 parents 783ab4e + 635d13c commit f32c37c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/StringTagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,11 @@ public function setCanCreate($canCreate)

return $this;
}

public function performReadonlyTransformation()
{
$field = parent::performReadonlyTransformation();
$field->setValue(implode(', ', $this->Value()));
return $field;
}
}
34 changes: 19 additions & 15 deletions tests/StringTagFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,26 @@ public function testSchemaIsAddedToAttributes()
$this->assertNotEmpty($attributes['data-schema']);
}

/**
* Ensure a source of tags matches the given string tag names
*
* @param array $expected
* @param DataList $actualSource
*/
protected function compareTagLists(array $expected, DataList $actualSource)
public function testPerformReadonlyTransformation()
{
$actual = array_keys($actualSource->map('ID', 'Title')->toArray());
sort($expected);
sort($actual);

$this->assertEquals(
$expected,
$actual
);
$field = new StringTagField('Tags');
$field->setSource(['Test1', 'Test2', 'Test3']);

// Ensure a single value can be rendered
$field->setValue(['Test2']);
$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());
}

/**
Expand Down

0 comments on commit f32c37c

Please sign in to comment.