mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #793 from stephenmcm/feat-disableShortcode
Optional disable $UserDefinedForm
This commit is contained in:
commit
dc226cf8ba
5
_config/config.yml
Normal file
5
_config/config.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
Name: userformsconfig
|
||||||
|
---
|
||||||
|
SilverStripe\UserForms\Control\UserDefinedFormController:
|
||||||
|
disable_form_content_shortcode: false
|
@ -108,7 +108,8 @@ class UserDefinedFormController extends PageController
|
|||||||
*/
|
*/
|
||||||
public function index(HTTPRequest $request = null)
|
public function index(HTTPRequest $request = null)
|
||||||
{
|
{
|
||||||
if ($this->Content && $form = $this->Form()) {
|
$form = $this->Form();
|
||||||
|
if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) {
|
||||||
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||||
if ($hasLocation) {
|
if ($hasLocation) {
|
||||||
/** @see Requirements_Backend::escapeReplacement */
|
/** @see Requirements_Backend::escapeReplacement */
|
||||||
|
@ -257,7 +257,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
$controller = new UserDefinedFormController($form);
|
$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());
|
$index = new ArrayData($controller->index());
|
||||||
$parser = new CSSContentParser($index->renderWith(__CLASS__));
|
$parser = new CSSContentParser($index->renderWith(__CLASS__));
|
||||||
|
|
||||||
@ -276,6 +276,26 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
$this->checkTemplateIsCorrect($parser, $form);
|
$this->checkTemplateIsCorrect($parser, $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRenderingIntoTemplateWithDisabledInterpolation()
|
||||||
|
{
|
||||||
|
$form = $this->setupFormFrontend();
|
||||||
|
|
||||||
|
$controller = new UserDefinedFormController($form);
|
||||||
|
$controller->config()->set('disable_form_content_shortcode', 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);
|
||||||
|
|
||||||
|
// Assert Content has been rendered with the shortcode in place
|
||||||
|
$this->assertContains('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html);
|
||||||
|
// And the form in the $From area
|
||||||
|
$this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID));
|
||||||
|
// check for the input
|
||||||
|
$this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish a form for use on the frontend
|
* Publish a form for use on the frontend
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user