2015-07-24 04:37:48 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Model\Recipient;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Config;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
|
2018-01-24 03:17:03 +01:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
use SilverStripe\View\SSViewer;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
/**
|
|
|
|
* Controller that handles requests to EmailRecipient's
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $allowed_actions = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'edit',
|
|
|
|
'view',
|
|
|
|
'ItemEditForm',
|
|
|
|
'preview'
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* Renders a preview of the recipient email.
|
|
|
|
*/
|
|
|
|
public function preview()
|
|
|
|
{
|
2017-03-14 06:10:27 +01:00
|
|
|
// Enable theme for preview (may be needed for Shortcodes)
|
2017-06-09 00:19:58 +02:00
|
|
|
Config::nest();
|
2017-08-11 01:33:06 +02:00
|
|
|
Config::modify()->set(SSViewer::class, 'theme_enabled', true);
|
2017-06-09 00:19:58 +02:00
|
|
|
|
2018-01-24 03:17:03 +01:00
|
|
|
$content = $this->customise([
|
2016-07-21 07:53:59 +02:00
|
|
|
'Body' => $this->record->getEmailBodyContent(),
|
2018-01-24 03:17:03 +01:00
|
|
|
'HideFormData' => (bool) $this->record->HideFormData,
|
2016-07-21 07:53:59 +02:00
|
|
|
'Fields' => $this->getPreviewFieldData()
|
2018-01-24 03:17:03 +01:00
|
|
|
])->renderWith($this->record->EmailTemplate);
|
2017-06-09 00:19:58 +02:00
|
|
|
|
|
|
|
Config::unnest();
|
|
|
|
|
|
|
|
return $content;
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* Get some placeholder field values to display in the preview
|
2017-08-11 01:33:06 +02:00
|
|
|
*
|
2024-01-18 22:29:08 +01:00
|
|
|
* @return ArrayList<ArrayData>
|
2016-07-21 07:53:59 +02:00
|
|
|
*/
|
2017-08-11 01:33:06 +02:00
|
|
|
protected function getPreviewFieldData()
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
$data = ArrayList::create();
|
2021-01-17 10:53:41 +01:00
|
|
|
$fields = $this->record->Form()->Fields();
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
foreach ($fields as $field) {
|
2021-01-17 10:53:41 +01:00
|
|
|
if (!$field->showInReports()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-11 01:33:06 +02:00
|
|
|
$data->push(ArrayData::create([
|
2017-05-01 07:37:50 +02:00
|
|
|
'Name' => $field->dbObject('Name'),
|
|
|
|
'Title' => $field->dbObject('Title'),
|
|
|
|
'Value' => DBField::create_field('Varchar', '$' . $field->Name),
|
|
|
|
'FormattedValue' => DBField::create_field('Varchar', '$' . $field->Name)
|
2017-08-11 01:33:06 +02:00
|
|
|
]));
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $data;
|
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
}
|