diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index e24a80b15..10a3a1aeb 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -175,6 +175,15 @@ class HTMLText extends Text { return $this->Summary(); } + public function RAW() { + if ($this->processShortcodes) { + return ShortcodeParser::get_active()->parse($this->value); + } + else { + return $this->value; + } + } + /** * Return the value of the field with relative links converted to absolute urls (with placeholders parsed). * @return string @@ -184,12 +193,7 @@ class HTMLText extends Text { } public function forTemplate() { - if ($this->processShortcodes) { - return ShortcodeParser::get_active()->parse($this->value); - } - else { - return $this->value; - } + return $this->RAW(); } public function prepValueForDB($value) { diff --git a/model/fieldtypes/HTMLVarchar.php b/model/fieldtypes/HTMLVarchar.php index 0118efe39..44aa54434 100644 --- a/model/fieldtypes/HTMLVarchar.php +++ b/model/fieldtypes/HTMLVarchar.php @@ -21,6 +21,10 @@ class HTMLVarchar extends Varchar { } public function forTemplate() { + return $this->RAW(); + } + + public function RAW() { if ($this->processShortcodes) { return ShortcodeParser::get_active()->parse($this->value); } diff --git a/tests/model/HTMLTextTest.php b/tests/model/HTMLTextTest.php index 6a0367384..7bf3f908f 100644 --- a/tests/model/HTMLTextTest.php +++ b/tests/model/HTMLTextTest.php @@ -192,4 +192,26 @@ class HTMLTextTest extends SapphireTest { 'Removes any elements not in whitelist including text elements' ); } + + public function testShortCodeParsedInRAW() { + $parser = ShortcodeParser::get('HTMLTextTest'); + $parser->register('shortcode', function($arguments, $content, $parser, $tagName, $extra) { + return 'replaced'; + }); + ShortcodeParser::set_active('HTMLTextTest'); + /** @var HTMLText $field */ + $field = DBField::create_field('HTMLText', '

[shortcode]

'); + $this->assertEquals('

replaced

', $field->RAW()); + $this->assertEquals('

replaced

', (string)$field); + + $field->setOptions(array( + 'shortcodes' => false, + )); + + $this->assertEquals('

[shortcode]

', $field->RAW()); + $this->assertEquals('

[shortcode]

', (string)$field); + + + ShortcodeParser::set_active('default'); + } }