schantldev/statamic-formattach
Composer 安装命令:
composer require schantldev/statamic-formattach
包简介
README 文档
README
Statamic FormAttach is a Statamic addon that allows to easily attach any files to form submission mails dynamically.
Features
This addon provides:
- A standard PDF attachment for form submissions1
- Support for any other attachment(s) you might need to add dynamically
How to Install
Install the addon using composer.
composer require schantldev/statamic-formattach
Publish the configuration file.
php artisan vendor:publish --tag=statamic-formattach-config
Swap out the send email job in your statamic/forms.php config file.
/* |-------------------------------------------------------------------------- | 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,
How to Use
After publishing the config file, you will be able to add attachments to any forms you wish. There's an array with the form handle and attachments to possibly be added.
'forms' => [ 'form_handle' => [ // \SchantlDev\Statamic\FormAttach\Attachments\AttachPdf::class, ], ],
Attaching PDFs
There is a default attachment that will generate a PDF using Spatie's Browsershot package1. In the config, you can find more settings for choosing a paper size and setting a custom logo. If that's not enough, you can opt in to publish the view[^3] and adjust it to your needs or create your own custom attachment.
php artisan vendor:publish --tag=statamic-formattach-views
Tip
If you wanna see a live preview while working on the view, there's a way! There are two routes you can use for your already saved submission:
- as HTML: submissions/{submission_id}/preview
- as PDF: submissions/{submission_id}/preview_pdf
Custom attachments
Sometimes, PDFs are just not enough or you need some more fine-grained control over the attachment. In that case, you can extend the FormAttachment class and implement its abstract method to provide any attachment in form of a mailable attachment2.
use Illuminate\Mail\Mailables\Attachment; abstract class FormAttachment { ... public function check(): bool; abstract public function attachment(): ?Attachment; }
Controlling whether to add an attachment
In the above excerpt, you can see a check() method that is present within a FormAttachment class. Use it to decide on whether to add an attachment or not. You can use the SubmissionHelper object that gives you access to the submission data, the form, the blueprint of the form and the config of the mail.
Example: (only attach PDF to owner mail - in a Statamic Peak context)
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'; } }
Contributing and Issues
Contributions and discussions are always welcome, no matter how large or small. If you happen to find an issue, please open up a Github issue or do a PR if you can.
Footnotes
-
The addon requires Browserhot for the PDF attachment to work out of the box. Please note that the addon will not install Browsershot for you as you might have already installed some version of it. Please install Browsershot directly into your project. ↩ ↩2
-
Refer to the offical Laravel documentation on how to create attachments in various ways. ↩
schantldev/statamic-formattach 适用场景与选型建议
schantldev/statamic-formattach 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 438 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 schantldev/statamic-formattach 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 schantldev/statamic-formattach 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 438
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-07-18