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(); $editableColumns = new GridFieldEditableColumns();
$fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses(); $fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
$editableColumns->setDisplayFields([ $editableColumns->setDisplayFields([
'ClassName' => [ 'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
'callback' => function ($record, $column, $grid) use ($fieldClasses) { if ($record instanceof EditableFormField) {
if ($record instanceof EditableFormField) { return $record->getInlineClassnameField($column, $fieldClasses);
return $record->getInlineClassnameField($column, $fieldClasses);
}
} }
], },
'Title' => [ 'Title' => function ($record, $column, $grid) {
'callback' => function ($record, $column, $grid) { if ($record instanceof EditableFormField) {
if ($record instanceof EditableFormField) { return $record->getInlineTitleField($column);
return $record->getInlineTitleField($column);
}
} }
] }
]); ]);
$config = GridFieldConfig::create() $config = GridFieldConfig::create()

View File

@ -176,17 +176,17 @@ class GridFieldAddClassesButton implements GridField_HTMLProvider, GridField_Act
if (!$buttonName) { if (!$buttonName) {
// provide a default button name, can be changed by calling {@link setButtonName()} on this component // provide a default button name, can be changed by calling {@link setButtonName()} on this component
$objectName = $singleton->i18n_singular_name(); $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, $grid,
$this->getAction(), $this->getAction(),
$buttonName, $buttonName,
$this->getAction(), $this->getAction(),
array() array()
); );
$addAction->setAttribute('data-icon', 'add'); $addAction->addExtraClass('font-icon-plus btn btn-primary');
if ($this->getButtonClass()) { if ($this->getButtonClass()) {
$addAction->addExtraClass($this->getButtonClass()); $addAction->addExtraClass($this->getButtonClass());

View File

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

View File

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