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 Name: userformsconfig
--- ---
SilverStripe\UserForms\Control\UserDefinedFormController: 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 * where the form should be rendered into. If it does not exist
* then default back to $Form. * then default back to $Form.
* *
* @return array|Object * @return array
*/ */
public function index(HTTPRequest $request = null) public function index(HTTPRequest $request = null)
{ {
if ($this->config()->disable_form_content_interpolation) { $form = $this->Form();
return $this; if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) {
}
if ($this->Content && $form = $this->Form()) {
$hasLocation = stristr($this->Content, '$UserDefinedForm'); $hasLocation = stristr($this->Content, '$UserDefinedForm');
if ($hasLocation) { if ($hasLocation) {
/** @see Requirements_Backend::escapeReplacement */ /** @see Requirements_Backend::escapeReplacement */

View File

@ -280,18 +280,18 @@ class UserDefinedFormControllerTest extends FunctionalTest
$form = $this->setupFormFrontend(); $form = $this->setupFormFrontend();
$controller = new UserDefinedFormController($form); $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 // check to see if $Form is replaced to inside the content
$index = new ArrayData($controller->index()); $index = new ArrayData($controller->index());
$html = $index->renderWith(__CLASS__); $html = $index->renderWith(__CLASS__);
$parser = new CSSContentParser($html); $parser = new CSSContentParser($html);
// Assert no Content has been rendered // Assert Content has been rendered with the shortcode in place
$this->assertNotContains('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html); $this->assertContains('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html);
// And no form // And the form in the $From area
$this->assertArrayNotHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID)); $this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID));
// check for the input // check for the input
$this->assertArrayNotHasKey(0, $parser->getBySelector('input.text')); $this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
} }
/** /**