FIX: Fixes needed to adapt to whitespace changes.

API: Whitespace trimmed from custom form field templates

The introduction of trailing newlines on all template files introduced
some changes that needed to be made.

Notably, whitespace has been trimmed from rendered form field templates.
This is the minimal impact to SilverStripe developers, as it preserves
the behaviour of the default field types, but I’ve still noted as a
change.
This commit is contained in:
Sam Minnee 2016-01-07 10:27:46 +13:00
parent 3ee8f505b7
commit 4aa50534d5
3 changed files with 29 additions and 4 deletions

View File

@ -0,0 +1,16 @@
# 3.4.0 (unreleased)
## Upgrading notes
Upgrading from 3.3 to 3.4 shouldn't require any code changes.
Note that if you are upgrading from 3.1, you should review the [3.2 upgrade notes](3.2.0).
### Other changes to be aware of
These changes are unlikely to affect your upgrade, but we've noted them just in case you had unusual project code that
was affected by these:
* When FormFields are rendered, leading & trailing whitespace is now stripped. The resulting HTML for form fields is
the same for the default fields, but if you have a custom form field that is relying on trailing whitespace being
outputted.

View File

@ -839,7 +839,16 @@ class FormField extends RequestHandler {
$this->extend('onBeforeRender', $this);
return $context->renderWith($this->getTemplates());
$result = $context->renderWith($this->getTemplates());
// Trim whitespace from the result, so that trailing newlines are supressed. Works for strings and HTMLText values
if(is_string($result)) {
$result = trim($result);
} else if($result instanceof DBField) {
$result->setValue(trim($result->getValue()));
}
return $result;
}
/**

View File

@ -134,7 +134,7 @@ class SSViewerTest extends SapphireTest {
public function render($templateString, $data = null, $cacheTemplate = false) {
$t = SSViewer::fromString($templateString, $cacheTemplate);
if(!$data) $data = new SSViewerTestFixture();
return $t->process($data);
return trim(''.$t->process($data));
}
public function testRequirements() {
@ -1095,10 +1095,10 @@ after')
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
$template = new SSViewer(array('Page'));
$self->assertEquals('Foo', $template->process(new ArrayData(array())));
$self->assertEquals("Foo\n\n", $template->process(new ArrayData(array())));
$template = new SSViewer(array('Shortcodes', 'Page'));
$self->assertEquals('[file_link]', $template->process(new ArrayData(array())));
$self->assertEquals("[file_link]\n\n", $template->process(new ArrayData(array())));
});
}