├── src ├── Plugin.php ├── templates │ └── settings.twig ├── icon.svg └── Adapter.php ├── LICENSE.md └── composer.json /src/Plugin.php: -------------------------------------------------------------------------------- 1 | types[] = Adapter::class; 26 | } 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/templates/settings.twig: -------------------------------------------------------------------------------- 1 | {% import "_includes/forms" as forms %} 2 | 3 | {{ forms.autosuggestField({ 4 | label: "API Token"|t('mailcoach'), 5 | instructions: "The Mailcoach API token."|t('mailcoach'), 6 | id: 'apiToken', 7 | name: 'apiToken', 8 | value: adapter.apiToken, 9 | suggestEnvVars: true, 10 | errors: adapter.getErrors('apiToken') 11 | }) }} 12 | 13 | {{ forms.autosuggestField({ 14 | label: "Host"|t('mailcoach'), 15 | instructions: "The Mailcoach host. (By default this is `.mailcoach.app` but if you use self-hosted Mailcoach this is your own domain.)"|t('mailcoach'), 16 | id: 'host', 17 | name: 'host', 18 | value: adapter.host, 19 | suggestEnvVars: true, 20 | errors: adapter.getErrors('host') 21 | }) }} 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) :vendor_name 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spatie/craft-mailcoach", 3 | "description": "Mailcoach mailer adapter", 4 | "type": "craft-plugin", 5 | "license": "MIT", 6 | "support": { 7 | "email": "mailcoach@spatie.be", 8 | "issues": "https://github.com/spatie/craft-mailcoach/issues?state=open", 9 | "source": "https://github.com/spatie/craft-mailcoach", 10 | "docs": "https://github.com/spatie/craft-mailcoach", 11 | "rss": "https://github.com/spatie/craft-mailcoach/releases.atom" 12 | }, 13 | "require": { 14 | "php": ">=8.2", 15 | "craftcms/cms": "^5.0.0", 16 | "spatie/mailcoach-mailer": "^1.3.0" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Spatie\\CraftMailcoach\\": "src/" 21 | } 22 | }, 23 | "extra": { 24 | "handle": "mailcoach", 25 | "name": "Mailcoach", 26 | "developer": "Spatie", 27 | "documentationUrl": "https://github.com/spatie/craft-mailcoach" 28 | }, 29 | "config": { 30 | "sort-packages": true, 31 | "platform": { 32 | "php": "8.2" 33 | }, 34 | "allow-plugins": { 35 | "yiisoft/yii2-composer": true, 36 | "craftcms/plugin-installer": true 37 | } 38 | }, 39 | "require-dev": { 40 | "laravel/pint": "^1.25" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /src/Adapter.php: -------------------------------------------------------------------------------- 1 | Craft::t('mailcoach', 'API Token'), 26 | 'host' => Craft::t('mailcoach', 'Host'), 27 | ]; 28 | } 29 | 30 | public function behaviors(): array 31 | { 32 | $behaviors = parent::behaviors(); 33 | $behaviors['parser'] = [ 34 | 'class' => EnvAttributeParserBehavior::class, 35 | 'attributes' => [ 36 | 'apiToken', 37 | 'host', 38 | ], 39 | ]; 40 | 41 | return $behaviors; 42 | } 43 | 44 | protected function defineRules(): array 45 | { 46 | return [ 47 | [['apiToken', 'host'], 'required'], 48 | ]; 49 | } 50 | 51 | public function getSettingsHtml(): ?string 52 | { 53 | return Craft::$app->getView()->renderTemplate('mailcoach/settings', [ 54 | 'adapter' => $this, 55 | ]); 56 | } 57 | 58 | public function defineTransport(): MailcoachApiTransport 59 | { 60 | $transport = new MailcoachApiTransport(App::parseEnv($this->apiToken)); 61 | $transport->setHost(App::parseEnv($this->host)); 62 | 63 | return $transport; 64 | } 65 | } 66 | --------------------------------------------------------------------------------