Skip to content

Commit

Permalink
Logo upload + external url option in email templates form
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaybokaderanium committed Sep 11, 2023
1 parent 1fe362a commit a55b9bd
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/filament-email-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
//Default Logo
'logo' => 'media/email-templates/logo.png',

//Browsed Logo
'browsed_logo' => 'media/email-templates/logos',

//Logo size in pixels -> 200 pixels high is plenty big enough.
'logo_width' => '500',
'logo_height' => '126',
Expand Down
3 changes: 3 additions & 0 deletions database/migrations/create_email_templates_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ return new class extends Migration
$table->string('preheader', 191)->nullable()->comment('Only shows on some email clients below subject line');
$table->string('title', 50)->nullable()->comment('First line of email h1 string');
$table->text('content')->nullable();
$table->enum('logo_type', ['website_logo', 'browse_another', 'paste_url'])->default('website_logo');
$table->string('logo_img', 191)->nullable();
$table->string('logo_url', 191)->nullable();
$table->timestamps();
$table->softDeletes();
$table->unique(['key', 'language']);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/email/parts/_body.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<td align="center" valign="top" style="padding: 30px 10px 30px 10px;">
<a href="{{\Illuminate\Support\Facades\URL::to('/')}}" target="_blank" title="{{config('app.name')}}">
<img alt="{{config('app.name')}} Logo"
src="{{asset(config('filament-email-templates.logo'))}}"
src="{{asset($data['logo'])}}"
width="{{config('filament-email-templates.logo_width')}}"
height="{{config('filament-email-templates.logo_height')}}"
style="display: block; width: {{config('filament-email-templates.logo_width')}}px; max-width: {{config('filament-email-templates.logo_width')}}px; min-width: {{config
Expand Down
17 changes: 17 additions & 0 deletions src/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class EmailTemplate extends Model
'preheader',
'content',
'language',
'logo_type',
'logo_img',
'logo_url',

];

/**
Expand Down Expand Up @@ -158,6 +162,18 @@ public function getBase64EmailPreviewData()
public function getEmailPreviewData()
{
$model = self::createEmailPreviewData();
$logo = "";

switch ($this->logo_type) {
case "browse_another":
$logo = 'storage/'.$this->logo_img;
break;
case "paste_url":
$logo = $this->logo_url;
break;
default:
$logo = config('filament-email-templates.logo');
}

return [
'user' => $model->user,
Expand All @@ -166,6 +182,7 @@ public function getEmailPreviewData()
'preHeaderText' => $this->replaceTokens($this->preheader, $model),
'title' => $this->replaceTokens($this->title, $model),
'theme' => $this->theme->colours,
'logo' => $logo,
];
}

Expand Down
30 changes: 30 additions & 0 deletions src/Resources/EmailTemplateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use Visualbuilder\EmailTemplates\Contracts\FormHelperInterface;
use Visualbuilder\EmailTemplates\Models\EmailTemplate;
use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\Pages;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Get;

class EmailTemplateResource extends Resource
{
Expand Down Expand Up @@ -129,6 +132,33 @@ public static function form(Form $form): Form
->label(__('vb-email-templates::email-templates.form-fields-labels.content'))
->profile('default')
->default("<p>Dear ##user.firstname##, </p>"),

Radio::make('logo_type')
->label('Logo Type')
->options([
'website_logo' => 'Website logo',
'browse_another' => 'Browse another',
'paste_url' => 'Paste url',
])
->default('website_logo')
->inline()
->live(),

FileUpload::make('logo_img')
->label('Logo')
->hint('Browse image')
->hidden(fn (Get $get) => $get('logo_type') !== 'browse_another')
->directory(config('filament-email-templates.browsed_logo'))
->image()
->required(),

TextInput::make('logo_url')
->label('Logo')
->hint('Paste image url here')
->placeholder('https://www.example.com/media/test.png')
->hidden(fn (Get $get) => $get('logo_type') !== 'paste_url')
->activeUrl()
->required(),
]
),

Expand Down

0 comments on commit a55b9bd

Please sign in to comment.