Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FIX: Convert newlines to <br /> tags in string fields (fixes #1942)

  • Loading branch information...
commit 4a158454d68d84a50f0c06ba1e8780bb64989ca5 1 parent 1c7b4a0
@kinglozzer kinglozzer authored
View
7 model/fieldtypes/StringField.php
@@ -96,6 +96,13 @@ public function prepValueForDB($value) {
return parent::prepValueForDB($value);
}
}
+
+ /**
+ * @return string
+ */
+ public function forTemplate() {
+ return nl2br($this->XML());
+ }
/**
* Limit this field's content by a number of characters.
View
10 tests/model/StringFieldTest.php
@@ -5,6 +5,16 @@
*/
class StringFieldTest extends SapphireTest {
+
+ /**
+ * @covers StringField->forTemplate()
+ */
+ public function testForTemplate() {
+ $this->assertEquals(
+ "this is<br />\na test!",
+ DBField::create_field('StringFieldTest_MyStringField', "this is\na test!")->forTemplate()
+ );
+ }
/**
* @covers StringField->LowerCase()
Please sign in to comment.
Something went wrong with that request. Please try again.