shantldev / statamic-formattach
此包的最新版本(v1.0.1)没有提供许可信息。
v1.0.1
2024-07-18 11:08 UTC
Requires
- statamic/cms: ^5.0
Requires (Dev)
- orchestra/testbench: ^9.0
README
Statamic FormAttach
Statamic FormAttach 是一个 Statamic 插件,允许您动态地轻松将任何文件附加到表单提交邮件。
功能
此插件提供
- 标准 PDF 附件以供表单提交使用1
- 支持添加任何其他您可能需要的动态附件
安装方法
使用 composer 安装插件。
composer require schantldev/statamic-formattach
发布配置文件。
php artisan vendor:publish --tag=statamic-formattach-config
在您的 statamic/forms.php
配置文件中更换发送电子邮件任务。
/* |-------------------------------------------------------------------------- | Send Email Job |-------------------------------------------------------------------------- | | The class name of the job that will be used to send an email. | */ 'send_email_job' => \SchantlDev\Statamic\FormAttach\Forms\SendEmailWithAttachments::class,
使用方法
发布配置文件后,您将能够添加附件到您希望使用的任何表单。这里有一个包含表单句柄和可能添加的附件的数组。
'forms' => [ 'form_handle' => [ // \SchantlDev\Statamic\FormAttach\Attachments\AttachPdf::class, ], ],
附加 PDF
默认附件将使用 Spatie 的 Browsershot 包生成 PDF1。在配置中,您可以找到更多设置以选择纸张大小和设置自定义徽标。如果还不够,您可以选择发布视图[^3]并调整以满足您的需求,或者创建您自己的自定义附件。
php artisan vendor:publish --tag=statamic-formattach-views
提示
如果您在编辑视图时想查看实时预览,有方法!您可以使用以下两个路由查看已保存的提交
- 作为 HTML:submissions/{submission_id}/preview
- 作为 PDF:submissions/{submission_id}/preview_pdf
自定义附件
有时,PDF 不足以满足需求或您需要更精细的附件控制。在这种情况下,您可以扩展 FormAttachment
类并实现其抽象方法以提供任何形式的邮件附件2。
use Illuminate\Mail\Mailables\Attachment; abstract class FormAttachment { ... public function check(): bool; abstract public function attachment(): ?Attachment; }
控制是否添加附件
在上面的摘录中,您可以看到在 FormAttachment 类中存在一个 check()
方法。使用它来决定是否添加附件。您可以使用 SubmissionHelper 对象,该对象提供了对提交数据、表单、表单蓝图和邮件配置的访问。
示例:(仅在所有者邮件中附加 PDF - 在 Statamic Peak 上下文中)
namespace App\FormAttachments; use SchantlDev\Statamic\FormAttach\Attachments\AttachPdf; class PdfAttachment extends AttachPdf { public function check(): bool { return $this->submissionHelper->config['html'] == 'email/form_owner'; } }
贡献和问题
贡献和讨论总是受欢迎,无论大小。如果您发现任何问题,请打开 Github 问题或如果可能,请进行 PR。