silverstripe-userforms: Form not showing when Elemental is installed
Please note the following steps were taken on a project with which I have very little familiarity.
The problem (pre-investigation) I have the UserDefinedForm module and Elemental installed. My UserDefinedForm.ss template looks like the following:
$ElementalArea
$Form
However, the $Form is refusing to render and I initially had no ideas on why that wasn’t working.
The problem (post-investigation)
So after digging into the code of UserDefinedFormController, I deduced that the index action is blanking out the “Form” property, because $Content defaults to having “$UserDefinedForm” when you create the page.
EDIT: If you don’t know, the $Content field is completely removed / hidden in the CMS when you have Elemental installed. This made discovery of this problem tough!
The proposed solution Add a config that disables the blanking out of the “Form”. Modules like Elemental or Blocks could enable this OOTB.
ie.
public function index(HTTPRequest $request = null)
{
// Add this vvvv
if ($this->config()->disable_form_content_interpolation) {
return [];
}
if ($this->Content && $form = $this->Form()) {
$hasLocation = stristr($this->Content, '$UserDefinedForm');
if ($hasLocation) {
/** @see Requirements_Backend::escapeReplacement */
$formEscapedForRegex = addcslashes($form->forTemplate(), '\\$');
$content = preg_replace(
'/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i',
$formEscapedForRegex,
$this->Content
);
return [
'Content' => DBField::create_field('HTMLText', $content),
'Form' => ''
];
}
}
return [
'Content' => DBField::create_field('HTMLText', $this->Content),
'Form' => $this->Form()
];
}
Why not use Elemental UserForms?
- Maybe you don’t want the client to decide where the Form belongs on their page. (you just want it to be before or after all Elemental blocks)
- Maybe the client creates lots of forms and always forgets to add in the Elemental block. (As they’re used to this kind of workflow as that’s how their site always worked prior to SS4)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (9 by maintainers)
The important part of the above snippet (thanks @tardinha ) is that there also needs to be an
Afterheader to ensure the setting is not then overwritten by the userforms included configuration:app/_config/testforms.yml:This fix is however limited to project wide configuration, and is not configurable per subclass for reasons I was unable to uncover (in my testing, it is entirely possible I had misconfigured something). But the fix in userforms 5.3.0 does work.
For anyone following along at home…
@stephenmcm most likely in the next week or two
@ScopeyNZ we don’t define “bug fixes” based on whether they are breaking changes; breaking changes have to go into new major releases.
If it’s a new feature (which this is) then it goes into the next minor release, if it’s a bug fix, then it goes into the patch release.