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\Email\Email;
|
||||
use SilverStripe\Control\HTTP;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\i18n\i18n;
|
||||
@ -200,7 +201,7 @@ JS
|
||||
* @param array $data
|
||||
* @param Form $form
|
||||
*
|
||||
* @return \SilverStripe\Control\HTTPResponse
|
||||
* @return HTTPResponse
|
||||
*/
|
||||
public function process($data, $form)
|
||||
{
|
||||
@ -214,7 +215,7 @@ JS
|
||||
$submittedForm->write();
|
||||
}
|
||||
|
||||
$attachments = array();
|
||||
$attachments = [];
|
||||
$submittedFields = ArrayList::create();
|
||||
|
||||
foreach ($this->data()->Fields() as $field) {
|
||||
|
@ -6,8 +6,11 @@ use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Assets\FileFinder;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Email\Email;
|
||||
use SilverStripe\Core\Manifest\ModuleResource;
|
||||
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\FieldGroup;
|
||||
@ -27,18 +30,14 @@ use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipientCondition;
|
||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||
use SilverStripe\UserForms\UserForm;
|
||||
use SilverStripe\View\Requirements;
|
||||
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
|
||||
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
|
||||
@ -447,11 +446,6 @@ class EmailRecipient extends DataObject
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null)
|
||||
{
|
||||
if ($form = $this->Form()) {
|
||||
@ -461,11 +455,6 @@ class EmailRecipient extends DataObject
|
||||
return parent::canView($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
if ($form = $this->Form()) {
|
||||
@ -562,9 +551,8 @@ class EmailRecipient extends DataObject
|
||||
return [];
|
||||
}
|
||||
|
||||
$templateDirectory = ModuleResourceLoader::resourcePath(
|
||||
$parent->config()->get('email_template_directory')
|
||||
);
|
||||
$emailTemplateDirectory = $parent->config()->get('email_template_directory');
|
||||
$templateDirectory = ModuleResourceLoader::resourcePath($emailTemplateDirectory);
|
||||
|
||||
if (!$templateDirectory) {
|
||||
return [];
|
||||
@ -574,10 +562,21 @@ class EmailRecipient extends DataObject
|
||||
|
||||
foreach ($found as $key => $value) {
|
||||
$template = pathinfo($value);
|
||||
$templatePath = substr(
|
||||
$template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'],
|
||||
strlen(BASE_PATH) + 1
|
||||
);
|
||||
$absoluteFilename = $template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'];
|
||||
|
||||
// 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'];
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ namespace SilverStripe\UserForms\Model\Recipient;
|
||||
|
||||
use LogicException;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||
use SilverStripe\UserForms\Model\EditableFormField;
|
||||
|
||||
@ -142,31 +144,16 @@ class EmailRecipientCondition extends DataObject
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Parent()->canView($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Parent()->canEdit($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
|
@ -6,8 +6,8 @@ use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
@ -34,11 +34,11 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
Config::nest();
|
||||
Config::modify()->set(SSViewer::class, 'theme_enabled', true);
|
||||
|
||||
$content = $this->customise(ArrayData::create([
|
||||
$content = $this->customise([
|
||||
'Body' => $this->record->getEmailBodyContent(),
|
||||
'HideFormData' => $this->record->HideFormData,
|
||||
'HideFormData' => (bool) $this->record->HideFormData,
|
||||
'Fields' => $this->getPreviewFieldData()
|
||||
]))->renderWith($this->record->EmailTemplate);
|
||||
])->renderWith($this->record->EmailTemplate);
|
||||
|
||||
Config::unnest();
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
$Body
|
||||
|
||||
<% if HideFormData %>
|
||||
<% else %>
|
||||
<% if not $HideFormData %>
|
||||
<dl>
|
||||
<% loop Fields %>
|
||||
<dt><strong><% if Title %>$Title<% else %>$Name<% end_if %></strong></dt>
|
||||
<% loop $Fields %>
|
||||
<dt><strong><% if $Title %>$Title<% else %>$Name<% end_if %></strong></dt>
|
||||
<dd style="margin: 4px 0 14px 0">$FormattedValue</dd>
|
||||
<% end_loop %>
|
||||
</dl>
|
||||
|
@ -11,13 +11,12 @@ use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
|
||||
use SilverStripe\UserForms\Extension\UserFormValidator;
|
||||
use SilverStripe\UserForms\Model\EditableCustomRule;
|
||||
use SilverStripe\UserForms\Model\EditableFormField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
|
||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||
@ -165,7 +164,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$result = $recipient->getEmailTemplateDropdownValues();
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user