mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
Update default email_template_directory
Also if the overridded directory is empty - don’t display the template dropdown as this will cause a validation error preventing the user from saving the page.
This commit is contained in:
parent
5b59732c08
commit
e82dc5f121
@ -37,6 +37,8 @@ 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
|
||||||
@ -348,11 +350,6 @@ class EmailRecipient extends DataObject
|
|||||||
'Send email as plain text? (HTML will be stripped)'
|
'Send email as plain text? (HTML will be stripped)'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
DropdownField::create(
|
|
||||||
'EmailTemplate',
|
|
||||||
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILTEMPLATE', 'Email template'),
|
|
||||||
$this->getEmailTemplateDropdownValues()
|
|
||||||
)->addExtraClass('toggle-html-only'),
|
|
||||||
HTMLEditorField::create(
|
HTMLEditorField::create(
|
||||||
'EmailBodyHtml',
|
'EmailBodyHtml',
|
||||||
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILBODYHTML', 'Body')
|
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILBODYHTML', 'Body')
|
||||||
@ -366,6 +363,18 @@ class EmailRecipient extends DataObject
|
|||||||
LiteralField::create('EmailPreview', $preview)
|
LiteralField::create('EmailPreview', $preview)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$templates = $this->getEmailTemplateDropdownValues();
|
||||||
|
|
||||||
|
if ($templates) {
|
||||||
|
$fields->insertBefore(
|
||||||
|
DropdownField::create(
|
||||||
|
'EmailTemplate',
|
||||||
|
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILTEMPLATE', 'Email template')
|
||||||
|
)->addExtraClass('toggle-html-only'),
|
||||||
|
'EmailBodyHtml'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$fields->fieldByName('Root.EmailContent')->setTitle(_t(__CLASS__.'.EMAILCONTENTTAB', 'Email Content'));
|
$fields->fieldByName('Root.EmailContent')->setTitle(_t(__CLASS__.'.EMAILCONTENTTAB', 'Email Content'));
|
||||||
|
|
||||||
// Custom rules for sending this field
|
// Custom rules for sending this field
|
||||||
@ -546,13 +555,20 @@ class EmailRecipient extends DataObject
|
|||||||
$finder = new FileFinder();
|
$finder = new FileFinder();
|
||||||
$finder->setOption('name_regex', '/^.*\.ss$/');
|
$finder->setOption('name_regex', '/^.*\.ss$/');
|
||||||
|
|
||||||
$templateDirectory = UserDefinedForm::config()->get('email_template_directory');
|
$parent = $this->getFormParent();
|
||||||
// Handle cases where "userforms" might not be the base module directory, e.g. in a Travis build
|
|
||||||
if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory)
|
if (!$parent) {
|
||||||
&& substr($templateDirectory, 0, 10) === 'userforms/'
|
return [];
|
||||||
) {
|
|
||||||
$templateDirectory = substr($templateDirectory, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$templateDirectory = ModuleResourceLoader::resourcePath(
|
||||||
|
$parent->config()->get('email_template_directory')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$templateDirectory) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$found = $finder->find(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory);
|
$found = $finder->find(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory);
|
||||||
|
|
||||||
foreach ($found as $key => $value) {
|
foreach ($found as $key => $value) {
|
||||||
@ -562,14 +578,6 @@ class EmailRecipient extends DataObject
|
|||||||
strlen(BASE_PATH) + 1
|
strlen(BASE_PATH) + 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$defaultPrefixes = ['userforms/templates/', 'templates/'];
|
|
||||||
foreach ($defaultPrefixes as $defaultPrefix) {
|
|
||||||
// Remove default userforms folder if it's provided
|
|
||||||
if (substr($templatePath, 0, strlen($defaultPrefix)) === $defaultPrefix) {
|
|
||||||
$templatePath = substr($templatePath, strlen($defaultPrefix));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$templates[$templatePath] = $template['filename'];
|
$templates[$templatePath] = $template['filename'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ use SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest;
|
|||||||
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
|
use SilverStripe\Core\Config\Configurable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the user defined functionality to be applied to any {@link DataObject}
|
* Defines the user defined functionality to be applied to any {@link DataObject}
|
||||||
@ -43,6 +44,8 @@ use SilverStripe\View\Requirements;
|
|||||||
*/
|
*/
|
||||||
trait UserForm
|
trait UserForm
|
||||||
{
|
{
|
||||||
|
use Configurable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Built in extensions required by this page.
|
* Built in extensions required by this page.
|
||||||
*
|
*
|
||||||
@ -61,7 +64,7 @@ trait UserForm
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $email_template_directory = 'userforms/templates/email/';
|
private static $email_template_directory = 'silverstripe/userforms:templates/email/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should this module automatically upgrade on dev/build?
|
* Should this module automatically upgrade on dev/build?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user