FIX Use RAW instead of Value for parsing shortcodes

This commit is contained in:
Daniel Hensby 2016-06-30 15:46:23 +01:00
parent 3fe8d30c2c
commit b0f237bb3a
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
3 changed files with 36 additions and 6 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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', '<p>[shortcode]</p>');
$this->assertEquals('<p>replaced</p>', $field->RAW());
$this->assertEquals('<p>replaced</p>', (string)$field);
$field->setOptions(array(
'shortcodes' => false,
));
$this->assertEquals('<p>[shortcode]</p>', $field->RAW());
$this->assertEquals('<p>[shortcode]</p>', (string)$field);
ShortcodeParser::set_active('default');
}
}