Fix(shortcode) re-order if block check $UserDefinedForm in $this->Content. Rename config value to be clearer

This commit is contained in:
Stephen McMahon 2018-07-09 12:32:34 +10:00
parent ed1e9858af
commit 01520c22bd
3 changed files with 10 additions and 12 deletions

View File

@ -2,4 +2,4 @@
Name: userformsconfig
---
SilverStripe\UserForms\Control\UserDefinedFormController:
disable_form_content_interpolation: false
disable_form_content_shortcode: false

View File

@ -104,14 +104,12 @@ class UserDefinedFormController extends PageController
* where the form should be rendered into. If it does not exist
* then default back to $Form.
*
* @return array|Object
* @return array
*/
public function index(HTTPRequest $request = null)
{
if ($this->config()->disable_form_content_interpolation) {
return $this;
}
if ($this->Content && $form = $this->Form()) {
$form = $this->Form();
if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) {
$hasLocation = stristr($this->Content, '$UserDefinedForm');
if ($hasLocation) {
/** @see Requirements_Backend::escapeReplacement */

View File

@ -280,18 +280,18 @@ class UserDefinedFormControllerTest extends FunctionalTest
$form = $this->setupFormFrontend();
$controller = new UserDefinedFormController($form);
$controller->config()->set('disable_form_content_interpolation', true);
$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 no Content has been rendered
$this->assertNotContains('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html);
// And no form
$this->assertArrayNotHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID));
// 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->assertArrayNotHasKey(0, $parser->getBySelector('input.text'));
$this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
}
/**