From 8801790b660576f95165660e4209821561c14f96 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Sun, 17 Jan 2021 22:53:41 +1300 Subject: [PATCH] FIX Show correct fields in email preview Co-authored-by: Michael Caruana --- .../UserFormRecipientItemRequest.php | 12 ++--- .../UserFormRecipientItemRequestTest.php | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tests/Model/Recipient/UserFormRecipientItemRequestTest.php diff --git a/code/Model/Recipient/UserFormRecipientItemRequest.php b/code/Model/Recipient/UserFormRecipientItemRequest.php index c398cb5..bdfe544 100644 --- a/code/Model/Recipient/UserFormRecipientItemRequest.php +++ b/code/Model/Recipient/UserFormRecipientItemRequest.php @@ -53,16 +53,12 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest protected function getPreviewFieldData() { $data = ArrayList::create(); - - $fields = $this->record->Form()->Fields()->filter( - 'ClassName:not', - [ - EditableLiteralField::class, - EditableFormHeading::class, - ] - ); + $fields = $this->record->Form()->Fields(); foreach ($fields as $field) { + if (!$field->showInReports()) { + continue; + } $data->push(ArrayData::create([ 'Name' => $field->dbObject('Name'), 'Title' => $field->dbObject('Title'), diff --git a/tests/Model/Recipient/UserFormRecipientItemRequestTest.php b/tests/Model/Recipient/UserFormRecipientItemRequestTest.php new file mode 100644 index 0000000..65b20b3 --- /dev/null +++ b/tests/Model/Recipient/UserFormRecipientItemRequestTest.php @@ -0,0 +1,47 @@ +write(); + /** @var PolymorphicHasManyList $fields */ + $fields = $form->Fields(); + foreach (array_merge($falseClasses, $trueClasses) as $class) { + $fqcn = "$namespace\\$class"; + $obj = new $fqcn(); + $obj->Name = 'My' . $class; + $obj->write(); + $fields->add($obj); + } + $recipient = new EmailRecipient(); + $recipient->EmailAddress = 'to@example.com'; + $recipient->EmailFrom = 'from@example.com'; + $recipient->EmailTemplate = 'email/SubmittedFormEmail'; + $recipient->Form = $form; + $recipient->write(); + $recipient->setComponent('Form', $form); + $request = new UserFormRecipientItemRequest(null, null, $recipient, null, ''); + $html = $request->preview()->getValue(); + foreach ($falseClasses as $class) { + $this->assertNotContains('My' . $class, $html); + } + foreach ($trueClasses as $class) { + $this->assertContains('My' . $class, $html); + } + } +}