silverstripe-userforms/code/model/recipients/UserFormRecipientItemRequest.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2015-07-24 04:37:48 +02:00
<?php
/**
* Controller that handles requests to EmailRecipient's
*
* @package userforms
*/
2016-07-21 07:53:59 +02:00
class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
{
2015-07-24 04:37:48 +02:00
2016-07-21 07:53:59 +02:00
private static $allowed_actions = array(
'edit',
'view',
'ItemEditForm',
'preview'
);
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()
{
return $this->customise(new ArrayData(array(
'Body' => $this->record->getEmailBodyContent(),
'HideFormData' => $this->record->HideFormData,
'Fields' => $this->getPreviewFieldData()
)))->renderWith($this->record->EmailTemplate);
}
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
* @return ArrayList
*/
private function getPreviewFieldData()
{
$data = new ArrayList();
2015-07-24 04:37:48 +02:00
2016-07-21 07:53:59 +02:00
$fields = $this->record->Form()->Fields()->filter(array(
'ClassName:not' => 'EditableLiteralField',
'ClassName:not' => 'EditableFormHeading'
));
2015-07-24 04:37:48 +02:00
2016-07-21 07:53:59 +02:00
foreach ($fields as $field) {
$data->push(new ArrayData(array(
'Name' => $field->Name,
'Title' => $field->Title,
'Value' => '$' . $field->Name,
'FormattedValue' => '$' . $field->Name
)));
}
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
}