From 96c00677539b6932526668dbf3252704f0a79b60 Mon Sep 17 00:00:00 2001 From: cannycookie Date: Sat, 8 Jul 2023 23:10:01 +0000 Subject: [PATCH] Fix styling --- .php-cs-fixer.cache | 1 + src/Components/Iframe.php | 4 +- src/Components/SelectLanguage.php | 4 +- src/Contracts/TokenHelperInterface.php | 2 +- src/EmailTemplatesAuthServiceProvider.php | 13 +--- src/EmailTemplatesEventServiceProvider.php | 23 +++--- src/EmailTemplatesServiceProvider.php | 40 +++++----- src/Helpers/TokenHelper.php | 14 ++-- .../Controllers/EmailTemplateController.php | 16 ++-- src/Listeners/PasswordResetListener.php | 6 +- src/Listeners/UserLockoutListener.php | 6 +- src/Listeners/UserLoginListener.php | 3 +- src/Listeners/UserRegisteredListener.php | 3 +- src/Listeners/UserVerifiedListener.php | 8 +- src/Mail/UserLockedOutEmail.php | 7 +- src/Mail/UserLoginEmail.php | 13 ++-- src/Mail/UserPasswordResetSuccessEmail.php | 13 ++-- src/Mail/UserRegisteredEmail.php | 13 ++-- src/Mail/UserRequestPasswordResetEmail.php | 15 ++-- src/Mail/UserVerifiedEmail.php | 13 ++-- src/Mail/UserVerifyEmail.php | 11 ++- src/Models/EmailTemplate.php | 42 +++++++---- src/Notifications/UserLockoutNotification.php | 5 +- src/Notifications/UserLoginNotification.php | 4 +- .../UserPasswordResetNotification.php | 4 +- .../UserRegisteredNotification.php | 4 +- .../UserResetPasswordRequestNotification.php | 11 +-- .../UserVerifiedNotification.php | 16 +--- src/Resources/EmailTemplateResource.php | 75 ++++++++++++------- .../Pages/CreateEmailTemplate.php | 3 +- .../Pages/EditEmailTemplate.php | 2 +- .../Pages/ListEmailTemplates.php | 2 +- .../Pages/PreviewEmailTemplate.php | 35 +++------ src/Traits/BuildGenericEmail.php | 19 +++-- tests/Models/User.php | 2 +- tests/Pest.php | 2 +- tests/ResourcesTest.php | 28 +++---- tests/TestCase.php | 8 +- tests/factories/EmailTemplateFactory.php | 61 ++++++++------- .../create_email_templates_table.php | 9 +-- tests/migrations/create_users_table.php | 3 +- 41 files changed, 286 insertions(+), 277 deletions(-) create mode 100644 .php-cs-fixer.cache diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..0fc50f6 --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.2.7","version":"3.20.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"curly_braces_position":{"allow_single_line_empty_anonymous_classes":true},"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Mail\/UserLoginEmail.php":"329a82853b7d999ca83727ae4cfe4ad7","src\/Mail\/UserPasswordResetSuccessEmail.php":"424196536f4b5c1e732f0af0e4e20508","src\/Mail\/UserRequestPasswordResetEmail.php":"34697e6c43ac925f55457164ca3e824b","src\/Mail\/UserLockedOutEmail.php":"39c1e1953ca1fde457d8abb4e72c8cbe","src\/Mail\/UserRegisteredEmail.php":"1c340bc2c746d72b6bc467a531c4d88c","src\/Mail\/UserVerifiedEmail.php":"9586f0b8e9abc2d521df9bae4705677d","src\/Mail\/UserVerifyEmail.php":"0a7307753eae99b4ba2d7e028898d216","src\/Models\/EmailTemplate.php":"e450f46e8c68fe385ca92cbd9ca970b4","src\/Components\/SelectLanguage.php":"071f37f6f3e8f679598e08e7c4d56c69","src\/Components\/Iframe.php":"9f0ced5dd4f7d11a7d27624fcfd819d0","src\/EmailTemplatesServiceProvider.php":"12d61b0961bf00e887bd1916b28dd9c7","src\/EmailTemplatesEventServiceProvider.php":"e3b0e4919fdb2b75f52385234169afcd","src\/Listeners\/UserLockoutListener.php":"e48c86c86ea131c8dfc3e28585a5c20a","src\/Listeners\/UserRegisteredListener.php":"642372800010a71b7d294ad2c516afde","src\/Listeners\/UserLoginListener.php":"03e01dafc269e0296e243299bc02b2b7","src\/Listeners\/PasswordResetListener.php":"c834264e4c49a4ab9aaedfff3566e95b","src\/Listeners\/UserVerifiedListener.php":"c31c7a93b6f384b38524f965528b7893","src\/Notifications\/UserPasswordResetNotification.php":"ed76d4a73258f9a12580f615937bf425","src\/Notifications\/UserResetPasswordRequestNotification.php":"50a5de5d9d76e3b7c74687d7b69c8660","src\/Notifications\/UserLoginNotification.php":"b98d444c275a5dd81ca988b02c5f6ba7","src\/Notifications\/UserVerifiedNotification.php":"b6a2cabc8838bd894b8fb32118606d6a","src\/Notifications\/UserRegisteredNotification.php":"853bb60f5c70587e2c9cd0e7300f06d6","src\/Notifications\/UserLockoutNotification.php":"f02d74be244f4e21c3b14f591627c79f","src\/Traits\/BuildGenericEmail.php":"5bb5e10f82492a715a3cace242e9cb14","src\/Helpers\/TokenHelper.php":"48979b16417ba0d439a7098b4a81fa4f","src\/Http\/Controllers\/EmailTemplateController.php":"6ad4941a35bbc3144d2d9e4c5a2863d5","src\/EmailTemplatesFacade.php":"b6b04b23d3bce0ef20dab85bb7bc5a10","src\/EmailTemplates.php":"97042a283775026268c450b7deecacec","src\/Resources\/EmailTemplateResource\/Pages\/CreateEmailTemplate.php":"33c696e1aaba8d38b93f204ea63b3994","src\/Resources\/EmailTemplateResource\/Pages\/EditEmailTemplate.php":"daa6683e1dcc0d3a138a37516a3afb64","src\/Resources\/EmailTemplateResource\/Pages\/PreviewEmailTemplate.php":"a81f4bdfec107f9d407219dc67444c86","src\/Resources\/EmailTemplateResource\/Pages\/ListEmailTemplates.php":"e24886338fab775dad38495e7b0986dd","src\/Resources\/EmailTemplateResource.php":"d2d893bd56b60e0b4fb6e85b8a1fdcfa","src\/Contracts\/TokenHelperInterface.php":"abde3efddf3c32765a95912bca424b7e","src\/EmailTemplatesAuthServiceProvider.php":"3c25a71676aa2690bfac0e1659ed6374","tests\/TestCase.php":"f6ba91847024b037444f7c877794ae93","tests\/migrations\/create_email_templates_table.php":"95e3a38f1a7a360e7af2a46d54c7c460","tests\/migrations\/create_users_table.php":"a32112307e67b99b284af7038656af62","tests\/Pest.php":"b13737ea8aab41b228111a9702e70e94","tests\/Models\/User.php":"972aff9c0adb682d0e22bba4b7914492","tests\/ExampleTest.php":"9c85d3fc3571920ba5e59e6d460c5220","tests\/factories\/EmailTemplateFactory.php":"79137d76f9b6fa23981c8c1d304989cc","tests\/ResourcesTest.php":"ee435659fede5808fba7094d17e6aa32"}} \ No newline at end of file diff --git a/src/Components/Iframe.php b/src/Components/Iframe.php index b44ab87..096a90a 100644 --- a/src/Components/Iframe.php +++ b/src/Components/Iframe.php @@ -3,7 +3,6 @@ namespace Visualbuilder\EmailTemplates\Components; use Filament\Forms\Components\Component; -use Illuminate\Support\Str; class Iframe extends Component { @@ -30,7 +29,8 @@ protected function setUp(): void }); } - public static function make($name, $label = null, $src = null, $height = '800px', $width = '100%') { + public static function make($name, $label = null, $src = null, $height = '800px', $width = '100%') + { return new static($name, $label, $src, $height, $width); } } diff --git a/src/Components/SelectLanguage.php b/src/Components/SelectLanguage.php index ee10e93..1f8dfdb 100644 --- a/src/Components/SelectLanguage.php +++ b/src/Components/SelectLanguage.php @@ -8,7 +8,7 @@ class SelectLanguage extends Field { use HasOptions; - + protected string $view = 'vb-email-templates::forms.components.select-language'; - + } diff --git a/src/Contracts/TokenHelperInterface.php b/src/Contracts/TokenHelperInterface.php index 7d5442e..55c37df 100644 --- a/src/Contracts/TokenHelperInterface.php +++ b/src/Contracts/TokenHelperInterface.php @@ -5,4 +5,4 @@ interface TokenHelperInterface { public function replaceTokens($string, $model); -} \ No newline at end of file +} diff --git a/src/EmailTemplatesAuthServiceProvider.php b/src/EmailTemplatesAuthServiceProvider.php index e2ec0dc..92f07f2 100644 --- a/src/EmailTemplatesAuthServiceProvider.php +++ b/src/EmailTemplatesAuthServiceProvider.php @@ -3,17 +3,12 @@ namespace Visualbuilder\EmailTemplates; use App\Models\User; -use Illuminate\Auth\Events\Login; -use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Notifications\VerifyEmail; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -use Visualbuilder\EmailTemplates\Listeners\UserLoginListener; -use Visualbuilder\EmailTemplates\Listeners\UserRegisteredListener; use Visualbuilder\EmailTemplates\Mail\UserVerifyEmail; class EmailTemplatesAuthServiceProvider extends ServiceProvider { - /** * Register any other events for your application. * @@ -22,13 +17,13 @@ class EmailTemplatesAuthServiceProvider extends ServiceProvider public function boot() { parent::boot(); - - if(config('email-templates.send_emails.verification')){ + + if(config('email-templates.send_emails.verification')) { //Override default Laravel VerifyEmail notification toMail function VerifyEmail::toMailUsing(function (User $user, string $verificationUrl) { - return (new UserVerifyEmail($user , $verificationUrl )); + return (new UserVerifyEmail($user, $verificationUrl)); }); } } -} \ No newline at end of file +} diff --git a/src/EmailTemplatesEventServiceProvider.php b/src/EmailTemplatesEventServiceProvider.php index c5aa23d..b9fdd08 100644 --- a/src/EmailTemplatesEventServiceProvider.php +++ b/src/EmailTemplatesEventServiceProvider.php @@ -2,18 +2,17 @@ namespace Visualbuilder\EmailTemplates; -use Illuminate\Auth\Events\Registered; +use Illuminate\Auth\Events\Lockout; use Illuminate\Auth\Events\Login; use Illuminate\Auth\Events\PasswordReset; -use Illuminate\Auth\Events\Lockout; +use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Verified; +use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Visualbuilder\EmailTemplates\Listeners\PasswordResetListener; use Visualbuilder\EmailTemplates\Listeners\UserLockoutListener; use Visualbuilder\EmailTemplates\Listeners\UserLoginListener; use Visualbuilder\EmailTemplates\Listeners\UserRegisteredListener; use Visualbuilder\EmailTemplates\Listeners\UserVerifiedListener; -use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; - class EmailTemplatesEventServiceProvider extends ServiceProvider { @@ -24,22 +23,22 @@ class EmailTemplatesEventServiceProvider extends ServiceProvider */ protected $listen = [ Login::class => [ - UserLoginListener::class + UserLoginListener::class, ], Registered::class => [ UserRegisteredListener::class, ], PasswordReset::class => [ - PasswordResetListener::class + PasswordResetListener::class, ], Lockout::class => [ - UserLockoutListener::class + UserLockoutListener::class, ], Verified::class => [ - UserVerifiedListener::class - ] + UserVerifiedListener::class, + ], ]; - + /** * Register any other events for your application. * @@ -48,7 +47,7 @@ class EmailTemplatesEventServiceProvider extends ServiceProvider public function boot() { parent::boot(); - + // } -} \ No newline at end of file +} diff --git a/src/EmailTemplatesServiceProvider.php b/src/EmailTemplatesServiceProvider.php index b761d52..591b494 100644 --- a/src/EmailTemplatesServiceProvider.php +++ b/src/EmailTemplatesServiceProvider.php @@ -3,11 +3,9 @@ namespace Visualbuilder\EmailTemplates; use Filament\PluginServiceProvider; -use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Request; +use Illuminate\Support\Facades\Route; use Spatie\LaravelPackageTools\Commands\InstallCommand; use Spatie\LaravelPackageTools\Package; -use Illuminate\Support\Facades\Route; use Visualbuilder\EmailTemplates\Contracts\TokenHelperInterface; use Visualbuilder\EmailTemplates\Helpers\TokenHelper; use Visualbuilder\EmailTemplates\Http\Controllers\EmailTemplateController; @@ -15,7 +13,6 @@ class EmailTemplatesServiceProvider extends PluginServiceProvider { - protected array $resources = [ EmailTemplateResource::class, ]; @@ -24,33 +21,36 @@ class EmailTemplatesServiceProvider extends PluginServiceProvider 'vb-email-templates-styles' => 'https://cdn.jsdelivr.net/gh/lipis/flag-icons@6.6.6/css/flag-icons.min.css', ]; - public function configurePackage(Package $package): void { + public function configurePackage(Package $package): void + { $package->name("filament-email-templates") ->hasMigrations(['create_email_templates_table']) ->hasConfigFile(['email-templates', 'filament-tiptap-editor']) ->hasAssets() ->hasViews('vb-email-templates') ->runsMigrations() - ->hasInstallCommand(function(InstallCommand $command) { - $command->startWith(function(InstallCommand $command) { - $command->info('Installing Email Templates'); - })->publishConfigFile() - ->publishAssets() - ->publishMigrations() - ->askToRunMigrations() - ->endWith(function(InstallCommand $command) { - $command->info('All Done'); - }); - }); + ->hasInstallCommand(function (InstallCommand $command) { + $command->startWith(function (InstallCommand $command) { + $command->info('Installing Email Templates'); + })->publishConfigFile() + ->publishAssets() + ->publishMigrations() + ->askToRunMigrations() + ->endWith(function (InstallCommand $command) { + $command->info('All Done'); + }); + }); } - public function register() { + public function register() + { parent::register(); $this->app->singleton(TokenHelperInterface::class, TokenHelper::class); $this->app->register(EmailTemplatesEventServiceProvider::class); } - public function boot() { + public function boot() + { parent::boot(); if($this->app->runningInConsole()) { $this->publishResources(); @@ -61,7 +61,8 @@ public function boot() { $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'vb-email-templates'); } - protected function publishResources() { + protected function publishResources() + { $this->publishes([ __DIR__ .'/../database/seeders/EmailTemplateSeeder.php' => database_path('seeders/EmailTemplateSeeder.php'), @@ -85,5 +86,4 @@ public function registerRoutes() { Route::get('/admin/email-templates/{record}/preview', [EmailTemplateController::class, 'preview'])->name('email-template.preview'); } - } diff --git a/src/Helpers/TokenHelper.php b/src/Helpers/TokenHelper.php index 0fd34c4..b576ee8 100644 --- a/src/Helpers/TokenHelper.php +++ b/src/Helpers/TokenHelper.php @@ -11,7 +11,7 @@ public function replaceTokens($content, $models) { // Replace singular tokens. // These are for password reset and email verification - if(isset($models->tokens)){ + if(isset($models->tokens)) { if (isset($models->tokens->tokenUrl)) { $content = str_replace('##tokenURL##', $models->tokens->tokenUrl, $content); } @@ -54,7 +54,7 @@ public function replaceTokens($content, $models) } } - $button = self::buildEmailButton($content); + $button = self::buildEmailButton($content); $content = self::replaceButtonToken($content, $button); return $content; @@ -72,23 +72,23 @@ public static function buildEmailButton($content) } if ($check1 && $check2) { return View::make('vb-email-templates::email.parts._button', [ - 'url' => $url, - 'title' => $title + 'url' => $url, + 'title' => $title, ]) ->render(); } }; + return ''; } public static function replaceButtonToken($content, $button) { - $search = "/(?<=##button).*?(?=##)/"; + $search = "/(?<=##button).*?(?=##)/"; $replace = ""; $content = preg_replace($search, $replace, $content); $content = str_replace('##button##', $button, $content); + return $content; } - - } diff --git a/src/Http/Controllers/EmailTemplateController.php b/src/Http/Controllers/EmailTemplateController.php index cc55488..9183fad 100644 --- a/src/Http/Controllers/EmailTemplateController.php +++ b/src/Http/Controllers/EmailTemplateController.php @@ -2,30 +2,30 @@ namespace Visualbuilder\EmailTemplates\Http\Controllers; -use App\Helpers\TokenHelper; use Illuminate\Routing\Controller; use Visualbuilder\EmailTemplates\Contracts\TokenHelperInterface; use Visualbuilder\EmailTemplates\Models\EmailTemplate; class EmailTemplateController extends Controller - { - public function preview($record, TokenHelperInterface $tokenHelper) { + public function preview($record, TokenHelperInterface $tokenHelper) + { $emailTemplate = EmailTemplate::findOrFail($record); $model = $emailTemplate->getEmailPreviewData(); $data = [ - 'user' => $model->user, - 'content' => $tokenHelper->replaceTokens($emailTemplate->content, $model), - 'subject' => $tokenHelper->replaceTokens($emailTemplate->subject, $model), + 'user' => $model->user, + 'content' => $tokenHelper->replaceTokens($emailTemplate->content, $model), + 'subject' => $tokenHelper->replaceTokens($emailTemplate->subject, $model), 'preHeaderText' => $tokenHelper->replaceTokens($emailTemplate->preheader, $model), - 'title' => $tokenHelper->replaceTokens($emailTemplate->title, $model) + 'title' => $tokenHelper->replaceTokens($emailTemplate->title, $model), ]; return view( - $emailTemplate->view_path, ['data' => $data] + $emailTemplate->view_path, + ['data' => $data] ); } } diff --git a/src/Listeners/PasswordResetListener.php b/src/Listeners/PasswordResetListener.php index 2f8818d..51b2c2b 100644 --- a/src/Listeners/PasswordResetListener.php +++ b/src/Listeners/PasswordResetListener.php @@ -3,8 +3,6 @@ namespace Visualbuilder\EmailTemplates\Listeners; use Illuminate\Auth\Events\PasswordReset; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use Visualbuilder\EmailTemplates\Notifications\UserVerifiedNotification; @@ -29,8 +27,8 @@ public function __construct() public function handle(PasswordReset $event) { $user = $event->user; - $user->notify(new UserVerifiedNotification()); + $user->notify(new UserVerifiedNotification()); + - } } diff --git a/src/Listeners/UserLockoutListener.php b/src/Listeners/UserLockoutListener.php index 4461eaa..5ac08cb 100644 --- a/src/Listeners/UserLockoutListener.php +++ b/src/Listeners/UserLockoutListener.php @@ -3,11 +3,9 @@ namespace Visualbuilder\EmailTemplates\Listeners; use Illuminate\Auth\Events\Login; -use Visualbuilder\EmailTemplates\Notifications\UserLoginNotification; class UserLockoutListener { - /** * Handle the event. * @@ -16,8 +14,8 @@ class UserLockoutListener */ public function handle(Login $event) { - $user = $event->user; - $user->notify(new UserLoNotification()); + $user = $event->user; + $user->notify(new UserLoNotification()); } } diff --git a/src/Listeners/UserLoginListener.php b/src/Listeners/UserLoginListener.php index 69fac7d..4a7d92b 100644 --- a/src/Listeners/UserLoginListener.php +++ b/src/Listeners/UserLoginListener.php @@ -14,7 +14,8 @@ class UserLoginListener * * @return void */ - public function handle(Login $event) { + public function handle(Login $event) + { $user = $event->user; $user->notify(new UserLoginNotification()); } diff --git a/src/Listeners/UserRegisteredListener.php b/src/Listeners/UserRegisteredListener.php index bd2746a..9b11e98 100644 --- a/src/Listeners/UserRegisteredListener.php +++ b/src/Listeners/UserRegisteredListener.php @@ -7,7 +7,6 @@ class UserRegisteredListener { - /** * Handle the event. * @@ -16,7 +15,7 @@ class UserRegisteredListener */ public function handle(Registered $event) { - if(config('email-templates.send_emails.new_user_registered')){ + if(config('email-templates.send_emails.new_user_registered')) { $user = $event->user; $user->notify(new UserLoginNotification()); } diff --git a/src/Listeners/UserVerifiedListener.php b/src/Listeners/UserVerifiedListener.php index e75e3d5..804653d 100644 --- a/src/Listeners/UserVerifiedListener.php +++ b/src/Listeners/UserVerifiedListener.php @@ -3,10 +3,6 @@ namespace Visualbuilder\EmailTemplates\Listeners; use Illuminate\Auth\Events\Verified; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Str; use Visualbuilder\EmailTemplates\Notifications\UserVerifiedNotification; class UserVerifiedListener @@ -30,8 +26,8 @@ public function __construct() public function handle(Verified $event) { $user = $event->user; - $user->notify(new UserVerifiedNotification()); + $user->notify(new UserVerifiedNotification()); + - } } diff --git a/src/Mail/UserLockedOutEmail.php b/src/Mail/UserLockedOutEmail.php index 919b542..a337269 100644 --- a/src/Mail/UserLockedOutEmail.php +++ b/src/Mail/UserLockedOutEmail.php @@ -10,7 +10,9 @@ class UserLockedOutEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; + use Queueable; + use SerializesModels; + use BuildGenericEmail; public $template = 'user-locked-out'; public $sendTo; @@ -20,7 +22,8 @@ class UserLockedOutEmail extends Mailable * * @return void */ - public function __construct($user, TokenHelperInterface $tokenHelper) { + public function __construct($user, TokenHelperInterface $tokenHelper) + { $this->sendTo = $user; $this->initializeTokenHelper($tokenHelper); } diff --git a/src/Mail/UserLoginEmail.php b/src/Mail/UserLoginEmail.php index 1a6721b..071cddc 100644 --- a/src/Mail/UserLoginEmail.php +++ b/src/Mail/UserLoginEmail.php @@ -10,19 +10,22 @@ class UserLoginEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; - + use Queueable; + use SerializesModels; + use BuildGenericEmail; + public $template = 'user-login'; public $user; public $sendTo; - + /** * Create a new message instance. * * @return void */ - public function __construct($user, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } diff --git a/src/Mail/UserPasswordResetSuccessEmail.php b/src/Mail/UserPasswordResetSuccessEmail.php index fdd2975..8eba553 100644 --- a/src/Mail/UserPasswordResetSuccessEmail.php +++ b/src/Mail/UserPasswordResetSuccessEmail.php @@ -10,19 +10,22 @@ class UserPasswordResetSuccessEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; - + use Queueable; + use SerializesModels; + use BuildGenericEmail; + public $template = 'user-password-reset-success'; public $user; public $sendTo; - + /** * Create a new message instance. * * @return void */ - public function __construct($user, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } diff --git a/src/Mail/UserRegisteredEmail.php b/src/Mail/UserRegisteredEmail.php index d6ddbb3..4236464 100644 --- a/src/Mail/UserRegisteredEmail.php +++ b/src/Mail/UserRegisteredEmail.php @@ -10,18 +10,21 @@ class UserRegisteredEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; - + use Queueable; + use SerializesModels; + use BuildGenericEmail; + public $template = 'user-welcome'; public $sendTo; - + /** * Create a new message instance. * * @return void */ - public function __construct($user, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } diff --git a/src/Mail/UserRequestPasswordResetEmail.php b/src/Mail/UserRequestPasswordResetEmail.php index ed18cc8..90b71df 100644 --- a/src/Mail/UserRequestPasswordResetEmail.php +++ b/src/Mail/UserRequestPasswordResetEmail.php @@ -10,22 +10,25 @@ class UserRequestPasswordResetEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; - + use Queueable; + use SerializesModels; + use BuildGenericEmail; + public $user; public $token; public $template = 'user-request-reset'; public $sendTo; - + /** * Create a new message instance. * * @return void */ - public function __construct($user, $token, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, $token, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->tokenUrl = $token; - $this->sendTo = $user->email; + $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } } diff --git a/src/Mail/UserVerifiedEmail.php b/src/Mail/UserVerifiedEmail.php index 9d8e4dd..91aac7d 100644 --- a/src/Mail/UserVerifiedEmail.php +++ b/src/Mail/UserVerifiedEmail.php @@ -10,18 +10,21 @@ class UserVerifiedEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; - + use Queueable; + use SerializesModels; + use BuildGenericEmail; + public $template = 'user-verified'; public $sendTo; - + /** * Create a new message instance. * * @return void */ - public function __construct($user, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } diff --git a/src/Mail/UserVerifyEmail.php b/src/Mail/UserVerifyEmail.php index 6936976..f1731cf 100644 --- a/src/Mail/UserVerifyEmail.php +++ b/src/Mail/UserVerifyEmail.php @@ -10,7 +10,9 @@ class UserVerifyEmail extends Mailable { - use Queueable, SerializesModels, BuildGenericEmail; + use Queueable; + use SerializesModels; + use BuildGenericEmail; public $user; public $verificationUrl; @@ -22,10 +24,11 @@ class UserVerifyEmail extends Mailable * * @return void */ - public function __construct($user, $token, TokenHelperInterface $tokenHelper) { - $this->user = $user; + public function __construct($user, $token, TokenHelperInterface $tokenHelper) + { + $this->user = $user; $this->verificationUrl = $token; - $this->sendTo = $user->email; + $this->sendTo = $user->email; $this->initializeTokenHelper($tokenHelper); } } diff --git a/src/Models/EmailTemplate.php b/src/Models/EmailTemplate.php index 3b934af..aa4f69e 100644 --- a/src/Models/EmailTemplate.php +++ b/src/Models/EmailTemplate.php @@ -12,7 +12,7 @@ use Visualbuilder\EmailTemplates\Database\Factories\EmailTemplateFactory; /** - * @property integer $id + * @property int $id * @property string $key * @property string $from * @property string $name @@ -31,7 +31,8 @@ */ class EmailTemplate extends Model { - use HasFactory, SoftDeletes; + use HasFactory; + use SoftDeletes; /** * @var array @@ -46,44 +47,51 @@ class EmailTemplate extends Model 'preheader', 'content', 'language', - 'send_to' + 'send_to', ]; - protected $casts = [ + protected $casts = [ 'deleted_at' => 'datetime:Y-m-d H:i:s', 'created_at' => 'datetime:Y-m-d H:i:s', 'updated_at' => 'datetime:Y-m-d H:i:s', ]; protected $dates = ['deleted_at']; - public function __construct(array $attributes = []) { + public function __construct(array $attributes = []) + { parent::__construct($attributes); $this->setTableFromConfig(); } - public function setTableFromConfig() { + public function setTableFromConfig() + { $this->table = config('email-templates.table_name'); } - protected static function newFactory() { + protected static function newFactory() + { return EmailTemplateFactory::new(); } - public function __toString() { + public function __toString() + { return $this->name ?? class_basename($this); } - public static function findEmailByKey($key, $language = null) { + public static function findEmailByKey($key, $language = null) + { return self::query() ->language($language ?? config('email-templates.default_locale')) ->where("key", $key) ->firstOrFail(); } - public static function getSendToSelectOptions() { + public static function getSendToSelectOptions() + { return collect(config('emailTemplate.recipients')); } - public static function getEmailPreviewData() { + public static function getEmailPreviewData() + { $model = (object) []; $userModel = config('email-templates.recipients')[ 0 ]; //Setup some data for previewing email template @@ -91,9 +99,10 @@ public static function getEmailPreviewData() { $model->tokens = (object) [ 'tokenUrl' => URL::to('/'), 'verificationUrl' => URL::to('/'), - 'expiresAt' => now() + 'expiresAt' => now(), ]; $model->plainText = Str::random(32); + return $model; } @@ -105,15 +114,18 @@ public static function getEmailPreviewData() { * * @return Builder */ - public function scopeLanguage(Builder $query, $language) { + public function scopeLanguage(Builder $query, $language) + { $languages = [$language, config('email-templates.default_locale')]; + return $query->whereIn('language', $languages) ->orderByRaw('field(language, ?, ?)', $languages); } - public function viewPath(): Attribute { + public function viewPath(): Attribute + { return new Attribute( - get: fn() => config('email-templates.template_view_path').'.'.$this->view + get: fn () => config('email-templates.template_view_path').'.'.$this->view ); } } diff --git a/src/Notifications/UserLockoutNotification.php b/src/Notifications/UserLockoutNotification.php index 842a561..62d1d5f 100644 --- a/src/Notifications/UserLockoutNotification.php +++ b/src/Notifications/UserLockoutNotification.php @@ -17,7 +17,7 @@ class UserLockoutNotification extends Notification * * @return void */ - public function __construct( ) + public function __construct() { } @@ -41,7 +41,7 @@ public function via($notifiable) */ public function toMail($notifiable) { - if(config('email-templates.send_emails.user_lockout')){ + if(config('email-templates.send_emails.user_lockout')) { return app(UserLockedOutEmail::class, ['user' => $notifiable]); } } @@ -56,5 +56,4 @@ public function toArray($notifiable) { return [ ]; } - } diff --git a/src/Notifications/UserLoginNotification.php b/src/Notifications/UserLoginNotification.php index b966c22..2fd61b0 100644 --- a/src/Notifications/UserLoginNotification.php +++ b/src/Notifications/UserLoginNotification.php @@ -7,7 +7,6 @@ use Illuminate\Notifications\Notification; use Visualbuilder\EmailTemplates\Mail\UserLoginEmail; - // implements ShouldQueue class UserLoginNotification extends Notification { @@ -18,7 +17,7 @@ class UserLoginNotification extends Notification * * @return void */ - public function __construct( ) + public function __construct() { } @@ -57,5 +56,4 @@ public function toArray($notifiable) { return [ ]; } - } diff --git a/src/Notifications/UserPasswordResetNotification.php b/src/Notifications/UserPasswordResetNotification.php index 60ab9f1..66c6260 100644 --- a/src/Notifications/UserPasswordResetNotification.php +++ b/src/Notifications/UserPasswordResetNotification.php @@ -5,7 +5,6 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; -use Visualbuilder\EmailTemplates\Mail\UserLoginEmail; use Visualbuilder\EmailTemplates\Mail\UserPasswordResetSuccessEmail; // implements ShouldQueue @@ -18,7 +17,7 @@ class UserPasswordResetNotification extends Notification * * @return void */ - public function __construct( ) + public function __construct() { } @@ -55,5 +54,4 @@ public function toArray($notifiable) { return [ ]; } - } diff --git a/src/Notifications/UserRegisteredNotification.php b/src/Notifications/UserRegisteredNotification.php index 13af134..57c1aab 100644 --- a/src/Notifications/UserRegisteredNotification.php +++ b/src/Notifications/UserRegisteredNotification.php @@ -5,7 +5,6 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; -use Visualbuilder\EmailTemplates\Mail\UserLoginEmail; use Visualbuilder\EmailTemplates\Mail\UserRegisteredEmail; // implements ShouldQueue @@ -18,7 +17,7 @@ class UserRegisteredNotification extends Notification * * @return void */ - public function __construct( ) + public function __construct() { } @@ -55,5 +54,4 @@ public function toArray($notifiable) { return [ ]; } - } diff --git a/src/Notifications/UserResetPasswordRequestNotification.php b/src/Notifications/UserResetPasswordRequestNotification.php index e6a0fca..00f1925 100644 --- a/src/Notifications/UserResetPasswordRequestNotification.php +++ b/src/Notifications/UserResetPasswordRequestNotification.php @@ -3,25 +3,23 @@ namespace Visualbuilder\EmailTemplates\Notifications; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Visualbuilder\EmailTemplates\Mail\UserRequestPasswordResetEmail; class UserResetPasswordRequestNotification extends Notification { use Queueable; - - public $tokenUrl; + public $tokenUrl; /** * Create a new notification instance. * * @return void */ - public function __construct( $tokenUrl ) + public function __construct($tokenUrl) { - $this->tokenUrl = $tokenUrl; + $this->tokenUrl = $tokenUrl; } /** @@ -43,7 +41,7 @@ public function via($notifiable) */ public function toMail($notifiable) { - return (new UserRequestPasswordResetEmail($notifiable , $this->tokenUrl )); + return (new UserRequestPasswordResetEmail($notifiable, $this->tokenUrl)); } /** @@ -56,5 +54,4 @@ public function toArray($notifiable) { return [ ]; } - } diff --git a/src/Notifications/UserVerifiedNotification.php b/src/Notifications/UserVerifiedNotification.php index 9a95c1e..b451670 100644 --- a/src/Notifications/UserVerifiedNotification.php +++ b/src/Notifications/UserVerifiedNotification.php @@ -3,26 +3,19 @@ namespace Visualbuilder\EmailTemplates\Notifications; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -use NotificationChannels\Telegram\TelegramMessage; -use Visualbuilder\EmailTemplates\Mail\UserRegisteredEmail; use Visualbuilder\EmailTemplates\Mail\UserVerifiedEmail; class UserVerifiedNotification extends Notification { use Queueable; - - - /** * Create a new notification instance. * * @return void */ - public function __construct( ) + public function __construct() { } @@ -35,7 +28,7 @@ public function __construct( ) */ public function via($notifiable) { - return array_merge($this->userVias($notifiable),['telegram']); + return array_merge($this->userVias($notifiable), ['telegram']); } /** @@ -46,7 +39,7 @@ public function via($notifiable) */ public function toMail($notifiable) { - if(config('email-templates.send_emails.user_verified')){ + if(config('email-templates.send_emails.user_verified')) { return app(UserVerifiedEmail::class, ['user' => $notifiable]); } } @@ -60,8 +53,7 @@ public function toMail($notifiable) public function toArray($notifiable) { return [ - + ]; } - } diff --git a/src/Resources/EmailTemplateResource.php b/src/Resources/EmailTemplateResource.php index 9cb87f8..e0e2e98 100644 --- a/src/Resources/EmailTemplateResource.php +++ b/src/Resources/EmailTemplateResource.php @@ -16,26 +16,27 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Str; -use Visualbuilder\EmailTemplates\Components\Iframe; use Visualbuilder\EmailTemplates\Components\SelectLanguage; use Visualbuilder\EmailTemplates\Models\EmailTemplate; use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\Pages; -use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\RelationManagers; class EmailTemplateResource extends Resource { - protected static ?string $model = EmailTemplate::class; + protected static ?string $model = EmailTemplate::class; protected static ?string $navigationIcon = 'heroicon-o-mail'; - public static function getModelLabel(): string { + public static function getModelLabel(): string + { return __('vb-email-templates::email-templates.resource_name.singular'); } - public static function getPluralModelLabel(): string { + public static function getPluralModelLabel(): string + { return __('vb-email-templates::email-templates.resource_name.plural'); } - public static function form(Form $form): Form { + public static function form(Form $form): Form + { $languages = self::prepareLang(); $templates = self::getTemplateViewList(); @@ -50,7 +51,7 @@ public static function form(Form $form): Form { TextInput::make('name') ->reactive() ->afterStateUpdated( - function( Closure $set, $state ) { + function (Closure $set, $state) { $set('key', Str::slug($state)); } ) @@ -67,7 +68,7 @@ function( Closure $set, $state ) { ->label(__('vb-email-templates::email-templates.form-fields-labels.key')) ->hint(__('vb-email-templates::email-templates.form-fields-labels.key-hint')) ->required() - ->unique(ignorable: fn($record) => $record), + ->unique(ignorable: fn ($record) => $record), SelectLanguage::make('language') ->options($languages), Select::make('view') @@ -103,12 +104,13 @@ function( Closure $set, $state ) { ), ] - ) + ), ] ); } - public static function prepareLang() { + public static function prepareLang() + { $languages = config('email-templates.languages'); $preparedLang = []; @@ -116,10 +118,12 @@ public static function prepareLang() { $preparedLang[ $langKey ] = ' '.$langVal[ "display" ]; } + return $preparedLang; } - public static function getTemplateViewList() { + public static function getTemplateViewList() + { $overrideDirectory = resource_path('views/vendor/vb-email-templates/email'); $packageDirectory = dirname(view(config('email-templates.template_view_path').'.default')->getPath()); @@ -142,24 +146,34 @@ public static function getTemplateViewList() { /** * Recursively get all files in a directory and children */ - private static function getFiles($dir, $basepath) { + private static function getFiles($dir, $basepath) + { $files = $subdirs = $subFiles = []; if($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { - if($entry == "." || $entry == "..") continue; - if(substr($entry, 0, 1) == '_') continue; + if($entry == "." || $entry == "..") { + continue; + } + if(substr($entry, 0, 1) == '_') { + continue; + } $entryPath = $dir.'/'.$entry; if(is_dir($entryPath)) { $subdirs[] = $entryPath; - } - else { + } else { $subFiles[] = str_replace( - '/', '.', str_replace( - '.blade.php', '', str_replace( - $basepath.'/', '', $entryPath - ) - ) + '/', + '.', + str_replace( + '.blade.php', + '', + str_replace( + $basepath.'/', + '', + $entryPath + ) + ) ); } } @@ -170,10 +184,12 @@ private static function getFiles($dir, $basepath) { $files = array_merge($files, self::getFiles($subdir, $basepath)); } } + return $files; } - public static function table(Table $table): Table { + public static function table(Table $table): Table + { return $table->columns( [ TextColumn::make('id'), @@ -196,7 +212,7 @@ public static function table(Table $table): Table { [ Tables\Actions\ViewAction::make() ->label("Preview") - ->hidden(fn($record) => $record->trashed()), + ->hidden(fn ($record) => $record->trashed()), Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), Tables\Actions\ForceDeleteAction::make(), @@ -212,17 +228,18 @@ public static function table(Table $table): Table { ); } - public static function getPages(): array { + public static function getPages(): array + { return [ - 'index' => Pages\ListEmailTemplates::route('/'), + 'index' => Pages\ListEmailTemplates::route('/'), 'create' => Pages\CreateEmailTemplate::route('/create'), - 'edit' => Pages\EditEmailTemplate::route('/{record}/edit'), - 'view' => Pages\PreviewEmailTemplate::route('/{record}'), + 'edit' => Pages\EditEmailTemplate::route('/{record}/edit'), + 'view' => Pages\PreviewEmailTemplate::route('/{record}'), ]; } - - public static function getEloquentQuery(): Builder { + public static function getEloquentQuery(): Builder + { return parent::getEloquentQuery() ->withoutGlobalScopes( [ diff --git a/src/Resources/EmailTemplateResource/Pages/CreateEmailTemplate.php b/src/Resources/EmailTemplateResource/Pages/CreateEmailTemplate.php index 13f4ee8..dc5c257 100644 --- a/src/Resources/EmailTemplateResource/Pages/CreateEmailTemplate.php +++ b/src/Resources/EmailTemplateResource/Pages/CreateEmailTemplate.php @@ -2,9 +2,8 @@ namespace Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\Pages; -use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; -use Filament\Pages\Actions; use Filament\Resources\Pages\CreateRecord; +use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; class CreateEmailTemplate extends CreateRecord { diff --git a/src/Resources/EmailTemplateResource/Pages/EditEmailTemplate.php b/src/Resources/EmailTemplateResource/Pages/EditEmailTemplate.php index b7a963c..0ebd374 100644 --- a/src/Resources/EmailTemplateResource/Pages/EditEmailTemplate.php +++ b/src/Resources/EmailTemplateResource/Pages/EditEmailTemplate.php @@ -2,9 +2,9 @@ namespace Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\Pages; -use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; use Filament\Pages\Actions; use Filament\Resources\Pages\EditRecord; +use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; class EditEmailTemplate extends EditRecord { diff --git a/src/Resources/EmailTemplateResource/Pages/ListEmailTemplates.php b/src/Resources/EmailTemplateResource/Pages/ListEmailTemplates.php index 9f2fe78..6b85353 100644 --- a/src/Resources/EmailTemplateResource/Pages/ListEmailTemplates.php +++ b/src/Resources/EmailTemplateResource/Pages/ListEmailTemplates.php @@ -2,9 +2,9 @@ namespace Visualbuilder\EmailTemplates\Resources\EmailTemplateResource\Pages; -use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; use Filament\Pages\Actions; use Filament\Resources\Pages\ListRecords; +use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; class ListEmailTemplates extends ListRecords { diff --git a/src/Resources/EmailTemplateResource/Pages/PreviewEmailTemplate.php b/src/Resources/EmailTemplateResource/Pages/PreviewEmailTemplate.php index 9953bdf..f484911 100644 --- a/src/Resources/EmailTemplateResource/Pages/PreviewEmailTemplate.php +++ b/src/Resources/EmailTemplateResource/Pages/PreviewEmailTemplate.php @@ -5,32 +5,21 @@ use Filament\Forms\Components\Card; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; -use Filament\Pages\Actions\EditAction; -use Filament\Resources\Form; -use Filament\Resources\Pages\EditRecord; -use Filament\Resources\Pages\Page; +use Filament\Forms\Components\TextInput; -use FilamentTiptapEditor\TiptapEditor; -use Illuminate\Contracts\Support\Htmlable; -use Illuminate\Database\Eloquent\Model; +use Filament\Resources\Form; use Filament\Resources\Pages\ViewRecord; -use Illuminate\Support\Str; use Visualbuilder\EmailTemplates\Components\Iframe; -use Visualbuilder\EmailTemplates\Components\SelectLanguage; use Visualbuilder\EmailTemplates\Models\EmailTemplate; use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource; -use Filament\Forms\Contracts\HasForms; -use Filament\Forms\Concerns\InteractsWithForms; -use Filament\Forms\Components\TextInput; class PreviewEmailTemplate extends ViewRecord { - protected static string $resource = EmailTemplateResource::class; public function getTitle(): string { - return __('vb-email-templates::email-templates.general-labels.preview-email', ['label'=>$this->record->name]); + return __('vb-email-templates::email-templates.general-labels.preview-email', ['label' => $this->record->name]); } protected $tokenHelper; @@ -49,6 +38,7 @@ protected function form(Form $form): Form { //View Email Template Form $emailTemplates = EmailTemplate::all()->pluck('name', 'id'); + return $form->schema( [ Card::make() @@ -65,7 +55,7 @@ protected function form(Form $form): Form TextInput::make('from') ->label(__('vb-email-templates::email-templates.form-fields-labels.email-from')) - ->disabled() + ->disabled(), ] ), Grid::make(['default' => 1]) @@ -77,7 +67,7 @@ protected function form(Form $form): Form TextInput::make('preheader') ->label(__('vb-email-templates::email-templates.form-fields-labels.header')) ->hint(__('vb-email-templates::email-templates.form-fields-labels.header-hint')) - ->disabled() + ->disabled(), ] ), Grid::make(['default' => 1]) @@ -85,30 +75,29 @@ protected function form(Form $form): Form [ Iframe::make('iframe'), ] - ) + ), ] - ) + ), ] ); } public function updatedEmailTemplateId($value) { - $test =- 1; + $test = -1; } protected function mutateFormDataBeforeFill(array $data): array { - foreach ($data as $key=>$value){ - $data[$key] = $this->tokenHelper->replaceTokens($value,$this); + foreach ($data as $key => $value) { + $data[$key] = $this->tokenHelper->replaceTokens($value, $this); } $data['emailTemplateId'] = $data['id']; + return $data; } - - protected function getForms(): array { return [ diff --git a/src/Traits/BuildGenericEmail.php b/src/Traits/BuildGenericEmail.php index dc4b352..1613fe9 100644 --- a/src/Traits/BuildGenericEmail.php +++ b/src/Traits/BuildGenericEmail.php @@ -10,7 +10,8 @@ trait BuildGenericEmail { private $tokenHelper; - public function initializeTokenHelper(TokenHelperInterface $tokenHelper) { + public function initializeTokenHelper(TokenHelperInterface $tokenHelper) + { $this->tokenHelper = $tokenHelper; } @@ -19,28 +20,30 @@ public function initializeTokenHelper(TokenHelperInterface $tokenHelper) { * * @return $this */ - public function build() { + public function build() + { $template = EmailTemplate::findEmailByKey($this->template, App::currentLocale()); if($this->attachment ?? false) { $this->attach( - $this->attachment->filepath, [ - 'as' => $this->attachment->filename, - 'mime' => $this->attachment->filetype + $this->attachment->filepath, + [ + 'as' => $this->attachment->filename, + 'mime' => $this->attachment->filetype, ] ); } $data = [ - 'content' => $this->tokenHelper->replaceTokens($template->content, $this), + 'content' => $this->tokenHelper->replaceTokens($template->content, $this), 'preHeaderText' => $this->tokenHelper->replaceTokens($template->preheader, $this), - 'title' => $this->tokenHelper->replaceTokens($template->title, $this) + 'title' => $this->tokenHelper->replaceTokens($template->title, $this), ]; return $this->from($template->from, config('app.name')) ->view($template->view_path) ->subject($this->tokenHelper->replaceTokens($template->subject, $this)) ->to($this->sendTo) - ->with(['data'=>$data]); + ->with(['data' => $data]); } } diff --git a/tests/Models/User.php b/tests/Models/User.php index a6b6089..ddcb7a3 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -33,4 +33,4 @@ protected static function newFactory(): UserFactory { return UserFactory::new(); } -} \ No newline at end of file +} diff --git a/tests/Pest.php b/tests/Pest.php index eaf6731..6f8c069 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -2,4 +2,4 @@ use Visualbuilder\EmailTemplates\Tests\TestCase; -uses(TestCase::class)->in(__DIR__); \ No newline at end of file +uses(TestCase::class)->in(__DIR__); diff --git a/tests/ResourcesTest.php b/tests/ResourcesTest.php index d77c48d..f94a870 100644 --- a/tests/ResourcesTest.php +++ b/tests/ResourcesTest.php @@ -1,15 +1,17 @@ call('create') ->assertHasNoFormErrors(); - + $this->assertDatabaseHas(EmailTemplate::class, [ 'key' => $storedData->data['key'], 'language' => $storedData->data['language'], @@ -98,7 +100,7 @@ ]) ->call('save') ->assertHasNoFormErrors(); - + $this->assertDatabaseHas(EmailTemplate::class, [ 'key' => $updatedData->data['key'], 'language' => $updatedData->data['language'], @@ -119,7 +121,7 @@ // delete and restore tests it('can delete email template', function () { $emailTemplate = EmailTemplate::factory()->create(); - + livewire(EditEmailTemplate::class, [ 'record' => $emailTemplate->getRouteKey(), ])->callPageAction(DeleteAction::class); @@ -129,7 +131,7 @@ it('can restore email template', function () { $emailTemplate = EmailTemplate::factory()->create(); - + livewire(EditEmailTemplate::class, [ 'record' => $emailTemplate->getRouteKey(), ])->callPageAction(DeleteAction::class); @@ -146,7 +148,7 @@ it('can force delete email template', function () { $emailTemplate = EmailTemplate::factory()->create(); - + livewire(EditEmailTemplate::class, [ 'record' => $emailTemplate->getRouteKey(), ])->callPageAction(DeleteAction::class); @@ -154,13 +156,13 @@ livewire(EditEmailTemplate::class, [ 'record' => $emailTemplate->getRouteKey(), ])->callPageAction(ForceDeleteAction::class); - + $this->assertModelMissing($emailTemplate); }); // preview tests it('can preview email template', function () { - get(EmailTemplateResource::getUrl('view',[ - 'record' => EmailTemplate::factory()->create() + get(EmailTemplateResource::getUrl('view', [ + 'record' => EmailTemplate::factory()->create(), ]))->assertSuccessful(); -}); \ No newline at end of file +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index 06ca53a..289e530 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,16 +6,16 @@ use BladeUI\Icons\BladeIconsServiceProvider; use Filament\FilamentServiceProvider; use Filament\Forms\FormsServiceProvider; -use Filament\Support\SupportServiceProvider; use Filament\Notifications\NotificationsServiceProvider; +use Filament\Support\SupportServiceProvider; use Filament\Tables\TablesServiceProvider; +use FilamentTiptapEditor\FilamentTiptapEditorServiceProvider; use Illuminate\Foundation\Testing\RefreshDatabase; -use Visualbuilder\EmailTemplates\EmailTemplatesServiceProvider; -use Visualbuilder\EmailTemplates\Tests\Models\User; use Livewire\LivewireServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; -use FilamentTiptapEditor\FilamentTiptapEditorServiceProvider; +use Visualbuilder\EmailTemplates\EmailTemplatesServiceProvider; +use Visualbuilder\EmailTemplates\Tests\Models\User; class TestCase extends Orchestra { diff --git a/tests/factories/EmailTemplateFactory.php b/tests/factories/EmailTemplateFactory.php index 81491c6..634bd65 100644 --- a/tests/factories/EmailTemplateFactory.php +++ b/tests/factories/EmailTemplateFactory.php @@ -6,39 +6,38 @@ use Illuminate\Support\Str; use Visualbuilder\EmailTemplates\Models\EmailTemplate; - class EmailTemplateFactory extends Factory { - /** - * The name of the factory's corresponding model. - * - * @var string - */ - protected $model = EmailTemplate::class; + /** + * The name of the factory's corresponding model. + * + * @var string + */ + protected $model = EmailTemplate::class; - /** - * Define the model's default state. - * - * @return array - */ - public function definition() - { - return [ - 'key' => Str::random(20), - 'language' => config('email-templates.default_locale'), - 'view' => config('email-templates.default_view'), - 'cc' => null, - 'bcc' => null, - 'send_to' => 'user', - 'from' => $this->faker->email, - 'name' => $this->faker->name, - 'preheader' => $this->faker->sentence, - 'subject' => $this->faker->sentence, - 'title' => $this->faker->sentence, - 'content' => $this->faker->text, - 'created_at' => now(), - 'updated_at' => now(), + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'key' => Str::random(20), + 'language' => config('email-templates.default_locale'), + 'view' => config('email-templates.default_view'), + 'cc' => null, + 'bcc' => null, + 'send_to' => 'user', + 'from' => $this->faker->email, + 'name' => $this->faker->name, + 'preheader' => $this->faker->sentence, + 'subject' => $this->faker->sentence, + 'title' => $this->faker->sentence, + 'content' => $this->faker->text, + 'created_at' => now(), + 'updated_at' => now(), 'deleted_at' => null, - ]; - } + ]; + } } diff --git a/tests/migrations/create_email_templates_table.php b/tests/migrations/create_email_templates_table.php index 687bffb..38256b1 100644 --- a/tests/migrations/create_email_templates_table.php +++ b/tests/migrations/create_email_templates_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. * @@ -13,14 +12,14 @@ */ public function up() { - Schema::create(config('email-templates.table_name') , function (Blueprint $table) { + Schema::create(config('email-templates.table_name'), function (Blueprint $table) { $table->increments('id'); $table->string('key', 191)->comment('Must be unique when combined with language'); - $table->string('language', 8)->default(config('email-templates.default_locale'),); + $table->string('language', 8)->default(config('email-templates.default_locale'), ); $table->string('name', 191)->nullable()->comment('Friendly Name'); $table->string('view', 191)->default(config('email-templates.default_view'))->comment('Blade Template to load into'); $table->string('from', 191)->nullable()->comment('From address to override system default'); - $table->string('send_to',191)->nullable()->comment('The Notifiable model class'); + $table->string('send_to', 191)->nullable()->comment('The Notifiable model class'); $table->json('cc')->nullable(); $table->json('bcc')->nullable(); $table->string('subject', 191)->nullable(); diff --git a/tests/migrations/create_users_table.php b/tests/migrations/create_users_table.php index d5286aa..e0c442b 100644 --- a/tests/migrations/create_users_table.php +++ b/tests/migrations/create_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */