mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
3ee8f505b7
commit
4aa50534d5
16
docs/en/04_Changelogs/3.4.0.md
Normal file
16
docs/en/04_Changelogs/3.4.0.md
Normal 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.
|
@ -839,7 +839,16 @@ class FormField extends RequestHandler {
|
|||||||
|
|
||||||
$this->extend('onBeforeRender', $this);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +134,7 @@ class SSViewerTest extends SapphireTest {
|
|||||||
public function render($templateString, $data = null, $cacheTemplate = false) {
|
public function render($templateString, $data = null, $cacheTemplate = false) {
|
||||||
$t = SSViewer::fromString($templateString, $cacheTemplate);
|
$t = SSViewer::fromString($templateString, $cacheTemplate);
|
||||||
if(!$data) $data = new SSViewerTestFixture();
|
if(!$data) $data = new SSViewerTestFixture();
|
||||||
return $t->process($data);
|
return trim(''.$t->process($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequirements() {
|
public function testRequirements() {
|
||||||
@ -1095,10 +1095,10 @@ after')
|
|||||||
|
|
||||||
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
|
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
|
||||||
$template = new SSViewer(array('Page'));
|
$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'));
|
$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())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user