mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Email templates for for submissions display correctly in preview
This commit is contained in:
parent
699dd32179
commit
5695c9585a
@ -8,6 +8,7 @@ use SilverStripe\Assets\Upload;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Email\Email;
|
use SilverStripe\Control\Email\Email;
|
||||||
use SilverStripe\Control\HTTP;
|
use SilverStripe\Control\HTTP;
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\i18n\i18n;
|
use SilverStripe\i18n\i18n;
|
||||||
@ -200,7 +201,7 @@ JS
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @param Form $form
|
* @param Form $form
|
||||||
*
|
*
|
||||||
* @return \SilverStripe\Control\HTTPResponse
|
* @return HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function process($data, $form)
|
public function process($data, $form)
|
||||||
{
|
{
|
||||||
@ -214,7 +215,7 @@ JS
|
|||||||
$submittedForm->write();
|
$submittedForm->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachments = array();
|
$attachments = [];
|
||||||
$submittedFields = ArrayList::create();
|
$submittedFields = ArrayList::create();
|
||||||
|
|
||||||
foreach ($this->data()->Fields() as $field) {
|
foreach ($this->data()->Fields() as $field) {
|
||||||
|
@ -6,8 +6,11 @@ use SilverStripe\Admin\LeftAndMain;
|
|||||||
use SilverStripe\Assets\FileFinder;
|
use SilverStripe\Assets\FileFinder;
|
||||||
use SilverStripe\CMS\Controllers\CMSMain;
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Email\Email;
|
use SilverStripe\Control\Email\Email;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleResource;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldGroup;
|
use SilverStripe\Forms\FieldGroup;
|
||||||
@ -27,18 +30,14 @@ use SilverStripe\ORM\ArrayList;
|
|||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
|
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
||||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipientCondition;
|
|
||||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||||
use SilverStripe\UserForms\UserForm;
|
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
|
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
||||||
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
|
||||||
use SilverStripe\Core\Config\Config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Form can have multiply members / emails to email the submission
|
* A Form can have multiply members / emails to email the submission
|
||||||
@ -447,11 +446,6 @@ class EmailRecipient extends DataObject
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Member
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
if ($form = $this->Form()) {
|
if ($form = $this->Form()) {
|
||||||
@ -461,11 +455,6 @@ class EmailRecipient extends DataObject
|
|||||||
return parent::canView($member);
|
return parent::canView($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Member
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function canEdit($member = null)
|
public function canEdit($member = null)
|
||||||
{
|
{
|
||||||
if ($form = $this->Form()) {
|
if ($form = $this->Form()) {
|
||||||
@ -562,9 +551,8 @@ class EmailRecipient extends DataObject
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$templateDirectory = ModuleResourceLoader::resourcePath(
|
$emailTemplateDirectory = $parent->config()->get('email_template_directory');
|
||||||
$parent->config()->get('email_template_directory')
|
$templateDirectory = ModuleResourceLoader::resourcePath($emailTemplateDirectory);
|
||||||
);
|
|
||||||
|
|
||||||
if (!$templateDirectory) {
|
if (!$templateDirectory) {
|
||||||
return [];
|
return [];
|
||||||
@ -574,10 +562,21 @@ class EmailRecipient extends DataObject
|
|||||||
|
|
||||||
foreach ($found as $key => $value) {
|
foreach ($found as $key => $value) {
|
||||||
$template = pathinfo($value);
|
$template = pathinfo($value);
|
||||||
$templatePath = substr(
|
$absoluteFilename = $template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'];
|
||||||
$template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'],
|
|
||||||
strlen(BASE_PATH) + 1
|
// Optionally remove vendor/ path prefixes
|
||||||
);
|
$resource = ModuleResourceLoader::singleton()->resolveResource($emailTemplateDirectory);
|
||||||
|
if ($resource instanceof ModuleResource && $resource->getModule()) {
|
||||||
|
$prefixToStrip = $resource->getModule()->getPath();
|
||||||
|
} else {
|
||||||
|
$prefixToStrip = BASE_PATH;
|
||||||
|
}
|
||||||
|
$templatePath = substr($absoluteFilename, strlen($prefixToStrip) + 1);
|
||||||
|
|
||||||
|
// Optionally remove "templates/" prefixes
|
||||||
|
if (substr($templatePath, 0, 10)) {
|
||||||
|
$templatePath = substr($templatePath, 10);
|
||||||
|
}
|
||||||
|
|
||||||
$templates[$templatePath] = $template['filename'];
|
$templates[$templatePath] = $template['filename'];
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ namespace SilverStripe\UserForms\Model\Recipient;
|
|||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use SilverStripe\CMS\Controllers\CMSMain;
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
|
|
||||||
@ -142,31 +144,16 @@ class EmailRecipientCondition extends DataObject
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Member
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
return $this->Parent()->canView($member);
|
return $this->Parent()->canView($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Member
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function canEdit($member = null)
|
public function canEdit($member = null)
|
||||||
{
|
{
|
||||||
return $this->Parent()->canEdit($member);
|
return $this->Parent()->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Member
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function canDelete($member = null)
|
public function canDelete($member = null)
|
||||||
{
|
{
|
||||||
return $this->canEdit($member);
|
return $this->canEdit($member);
|
||||||
|
@ -6,8 +6,8 @@ use SilverStripe\Core\Config\Config;
|
|||||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
|
||||||
|
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
use SilverStripe\View\SSViewer;
|
use SilverStripe\View\SSViewer;
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
Config::nest();
|
Config::nest();
|
||||||
Config::modify()->set(SSViewer::class, 'theme_enabled', true);
|
Config::modify()->set(SSViewer::class, 'theme_enabled', true);
|
||||||
|
|
||||||
$content = $this->customise(ArrayData::create([
|
$content = $this->customise([
|
||||||
'Body' => $this->record->getEmailBodyContent(),
|
'Body' => $this->record->getEmailBodyContent(),
|
||||||
'HideFormData' => $this->record->HideFormData,
|
'HideFormData' => (bool) $this->record->HideFormData,
|
||||||
'Fields' => $this->getPreviewFieldData()
|
'Fields' => $this->getPreviewFieldData()
|
||||||
]))->renderWith($this->record->EmailTemplate);
|
])->renderWith($this->record->EmailTemplate);
|
||||||
|
|
||||||
Config::unnest();
|
Config::unnest();
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
$Body
|
$Body
|
||||||
|
|
||||||
<% if HideFormData %>
|
<% if not $HideFormData %>
|
||||||
<% else %>
|
|
||||||
<dl>
|
<dl>
|
||||||
<% loop Fields %>
|
<% loop $Fields %>
|
||||||
<dt><strong><% if Title %>$Title<% else %>$Name<% end_if %></strong></dt>
|
<dt><strong><% if $Title %>$Title<% else %>$Name<% end_if %></strong></dt>
|
||||||
<dd style="margin: 4px 0 14px 0">$FormattedValue</dd>
|
<dd style="margin: 4px 0 14px 0">$FormattedValue</dd>
|
||||||
<% end_loop %>
|
<% end_loop %>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -11,13 +11,12 @@ use SilverStripe\Forms\Form;
|
|||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\Security\Member;
|
|
||||||
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
|
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
|
||||||
use SilverStripe\UserForms\Extension\UserFormValidator;
|
use SilverStripe\UserForms\Extension\UserFormValidator;
|
||||||
use SilverStripe\UserForms\Model\EditableCustomRule;
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
|
||||||
|
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
|
||||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||||
@ -165,7 +164,7 @@ class UserDefinedFormTest extends FunctionalTest
|
|||||||
$result = $recipient->getEmailTemplateDropdownValues();
|
$result = $recipient->getEmailTemplateDropdownValues();
|
||||||
|
|
||||||
// Installation path can be as a project when testing in Travis, so check partial match
|
// Installation path can be as a project when testing in Travis, so check partial match
|
||||||
$this->assertContains('templates/email/SubmittedFormEmail', key($result));
|
$this->assertContains('email/SubmittedFormEmail', key($result));
|
||||||
$this->assertSame('SubmittedFormEmail', current($result));
|
$this->assertSame('SubmittedFormEmail', current($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user