FIX Email preview renders as HTML, template selection works, use correct callbacks in GridField summary

This commit is contained in:
Robbie Averill 2017-08-24 15:15:36 +12:00
parent 1bbc473ed7
commit 4942ac35ad
4 changed files with 37 additions and 30 deletions

View File

@ -76,20 +76,16 @@ class UserFormFieldEditorExtension extends DataExtension
$editableColumns = new GridFieldEditableColumns();
$fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
$editableColumns->setDisplayFields([
'ClassName' => [
'callback' => function ($record, $column, $grid) use ($fieldClasses) {
if ($record instanceof EditableFormField) {
return $record->getInlineClassnameField($column, $fieldClasses);
}
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
if ($record instanceof EditableFormField) {
return $record->getInlineClassnameField($column, $fieldClasses);
}
],
'Title' => [
'callback' => function ($record, $column, $grid) {
if ($record instanceof EditableFormField) {
return $record->getInlineTitleField($column);
}
},
'Title' => function ($record, $column, $grid) {
if ($record instanceof EditableFormField) {
return $record->getInlineTitleField($column);
}
]
}
]);
$config = GridFieldConfig::create()

View File

@ -176,17 +176,17 @@ class GridFieldAddClassesButton implements GridField_HTMLProvider, GridField_Act
if (!$buttonName) {
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
$objectName = $singleton->i18n_singular_name();
$buttonName = _t('SilverStripe\\Forms\\GridField\\GridField.Add', 'Add {name}', array('name' => $objectName));
$buttonName = _t('SilverStripe\\Forms\\GridField\\GridField.Add', 'Add {name}', ['name' => $objectName]);
}
$addAction = new GridField_FormAction(
$addAction = GridField_FormAction::create(
$grid,
$this->getAction(),
$buttonName,
$this->getAction(),
array()
);
$addAction->setAttribute('data-icon', 'add');
$addAction->addExtraClass('font-icon-plus btn btn-primary');
if ($this->getButtonClass()) {
$addAction->addExtraClass($this->getButtonClass());

View File

@ -126,14 +126,9 @@ class EditableFormField extends DataObject
'Sort' => 'Int',
'Required' => 'Boolean',
'CustomErrorMessage' => 'Varchar(255)',
'CustomRules' => 'Text', // @deprecated from 2.0
'CustomSettings' => 'Text', // @deprecated from 2.0
'Migrated' => 'Boolean', // set to true when migrated
'ExtraClass' => 'Text', // from CustomSettings
'RightTitle' => 'Varchar(255)', // from CustomSettings
'ShowOnLoad' => 'Boolean(1)', // from CustomSettings
'ExtraClass' => 'Text',
'RightTitle' => 'Varchar(255)',
'ShowOnLoad' => 'Boolean(1)',
'ShowInSummary' => 'Boolean',
'Placeholder' => 'Varchar(255)',
'DisplayRulesConjunction' => 'Enum("And,Or","Or")',
@ -992,11 +987,11 @@ class EditableFormField extends DataObject
}
/**
* @return EditableFormFieldValidator
* @return EditableFormField\Validator
*/
public function getCMSValidator()
{
return EditableFormFieldValidator::create()
return EditableFormField\Validator::create()
->setRecord($this);
}

View File

@ -297,10 +297,15 @@ class EmailRecipient extends DataObject
// Only show the preview link if the recipient has been saved.
if (!empty($this->EmailTemplate)) {
$pageEditController = singleton(CMSPageEditController::class);
$pageEditController
->getRequest()
->setSession(Controller::curr()->getRequest()->getSession());
$preview = sprintf(
'<p><a href="%s" target="_blank" class="ss-ui-button">%s</a></p><em>%s</em>',
Controller::join_links(
singleton(CMSPageEditController::class)->getEditForm()->FormAction(),
$pageEditController->getEditForm()->FormAction(),
"field/EmailRecipients/item/{$this->ID}/preview"
),
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL', 'Preview email'),
@ -507,7 +512,7 @@ class EmailRecipient extends DataObject
if ($this->SendPlain) {
return DBField::create_field('HTMLText', $this->EmailBody)->Plain();
}
return DBField::create_field('HTMLText', $this->EmailBodyHtml)->RAW();
return DBField::create_field('HTMLText', $this->EmailBodyHtml);
}
/**
@ -524,15 +529,26 @@ class EmailRecipient extends DataObject
$templateDirectory = UserDefinedForm::config()->get('email_template_directory');
// Handle cases where "userforms" might not be the base module directory, e.g. in a Travis build
if (!file_exists($templateDirectory) && substr($templateDirectory, 0, 10) === 'userforms/') {
if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory)
&& substr($templateDirectory, 0, 10) === 'userforms/'
) {
$templateDirectory = substr($templateDirectory, 10);
}
$found = $finder->find(BASE_PATH . '/' . $templateDirectory);
$found = $finder->find(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory);
foreach ($found as $key => $value) {
$template = pathinfo($value);
$templatePath = substr(
$template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'],
strlen(BASE_PATH) + 1
);
$templates[$template['filename']] = $template['filename'];
$defaultPrefix = 'userforms/templates/';
// Remove default userforms folder if it's provided
if (substr($templatePath, 0, strlen($defaultPrefix)) === $defaultPrefix) {
$templatePath = substr($templatePath, strlen($defaultPrefix));
}
$templates[$templatePath] = $template['filename'];
}
return $templates;