mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Use RAW instead of Value for parsing shortcodes
This commit is contained in:
parent
3fe8d30c2c
commit
b0f237bb3a
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user