Add(config) create disable_form_content_interpolation option for ignoring $UserDefinedForm in $this->Content

This commit is contained in:
Stephen McMahon 2018-07-05 16:08:19 +10:00
parent 8ab6b0506a
commit 94192f4b66
3 changed files with 25 additions and 1 deletions

5
_config/config.yml Normal file
View File

@ -0,0 +1,5 @@
---
Name: userformsconfig
---
SilverStripe\UserForms\Control\UserDefinedFormController:
disable_form_content_interpolation: false

View File

@ -108,6 +108,9 @@ class UserDefinedFormController extends PageController
*/
public function index(HTTPRequest $request = null)
{
if ($this->config()->disable_form_content_interpolation) {
return [];
}
if ($this->Content && $form = $this->Form()) {
$hasLocation = stristr($this->Content, '$UserDefinedForm');
if ($hasLocation) {

View File

@ -255,7 +255,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$controller = new UserDefinedFormController($form);
// check to see if $Form is replaced to inside the content
// check to see if $Form is placed in the template
$index = new ArrayData($controller->index());
$parser = new CSSContentParser($index->renderWith(__CLASS__));
@ -274,6 +274,22 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->checkTemplateIsCorrect($parser, $form);
}
public function testRenderingIntoTemplateWithDisabledInterpolation()
{
$form = $this->setupFormFrontend();
$controller = new UserDefinedFormController($form);
$controller->config()->set('disable_form_content_interpolation', true);
// check to see if $Form is replaced to inside the content
$index = new ArrayData($controller->index());
$html = $index->renderWith(__CLASS__);
$parser = new CSSContentParser($html);
$this->assertContains('$UserDefinedForm', $html);
$this->checkTemplateIsCorrect($parser, $form);
}
/**
* Publish a form for use on the frontend
*