From d2f71be23e25d7480c04d9c5736e66bc4ed988f2 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Tue, 17 Nov 2020 17:10:33 +0100 Subject: [PATCH] unlayer buttons --- app/EmailTemplate.php | 18 ++++++-- app/Nova/EmailTemplate.php | 36 +++++++++++++++- app/TemplateVariables.php | 54 ++++++++++++++++++++++++ resources/views/unlayer/button.blade.php | 2 +- 4 files changed, 105 insertions(+), 5 deletions(-) diff --git a/app/EmailTemplate.php b/app/EmailTemplate.php index 2a3b5f8..78b238a 100644 --- a/app/EmailTemplate.php +++ b/app/EmailTemplate.php @@ -49,7 +49,19 @@ class EmailTemplate extends Model public static function fillWithContentFor($user, $content) { $content = self::fillWithRegex($user, $content, '/\{\{[^(% )]*\}\}/', '{{', '}}'); - return self::fillWithRegex($user, $content, '/%[^(% )]*%/', '%', '%'); + $content = self::fillWithRegex($user, $content, '/%[^(% )]*%/', '%', '%'); + return self::processLinks($user, $content); + } + + + public static function processLinks($user, $content) + { + return preg_replace_callback('/data-href-variable="([^(" )]*)"/', function($matches) use($user){ + $match = $matches[1]; + $url = $user->templateAttribute($match, null) ?? $matches[1]; + return sprintf('href="%s"', $url); + + }, $content); } /** @@ -67,8 +79,6 @@ class EmailTemplate extends Model return $user->templateAttribute($match, null) ?? $matches[0]; }, $content); - - } /** @@ -95,6 +105,8 @@ class EmailTemplate extends Model * @param null $color * @return string * @throws \Throwable + * @todo remove + * @deprecated */ public static function button($url, $label, $color = null) { diff --git a/app/Nova/EmailTemplate.php b/app/Nova/EmailTemplate.php index daf9d56..5e88b50 100644 --- a/app/Nova/EmailTemplate.php +++ b/app/Nova/EmailTemplate.php @@ -75,8 +75,42 @@ class EmailTemplate extends Resource 'name' => 'Contact', 'href' => route('contact.index') ], - ], + 'tools' => [ + 'custom#variable' => [ + 'properties' => [ + 'url_slug' => [ + 'editor' => [ + 'data' => [ + 'options' => [ + [ + 'label' => 'Accueil', + 'value' => 'home_url' + ], + [ + 'label' => 'Mon compte', + 'value' => 'my_account_url' + ], + [ + 'label' => 'Création mot de passe', + 'value' => 'complete_registration_url' + ], + [ + 'label' => 'Formulaire Contact', + 'value' => 'contact_url' + ], + [ + 'label' => 'Demander PDF', + 'value' => 'ask_pdf_url' + ] + ], + ] + ] + ] + ] + + ] + ] ])->savingCallback(function ($request, $attribute, $model, $html) { $model->update([ diff --git a/app/TemplateVariables.php b/app/TemplateVariables.php index ba7e74f..4689b70 100644 --- a/app/TemplateVariables.php +++ b/app/TemplateVariables.php @@ -55,6 +55,7 @@ trait TemplateVariables } + /** * Get the value of a template attribute using its getter. * @@ -74,6 +75,59 @@ trait TemplateVariables } + /** + * @return string + * @throws \Throwable + */ + public function getHomeUrlTemplate() + { + return url('/'); + } + + /** + * @return string + * @throws \Throwable + */ + public function getMyAccountUrlTemplate() + { + return $this->routeWithToken('account.index', [], now()->addDays(7)); + } + + + /** + * @return string + * @throws \Throwable + */ + public function getCompleteRegistrationUrlTemplate() + { + return $this->routeWithToken('account.complete-reg', [], now()->addDays(7)); + + } + + + /** + * @return string + * @throws \Throwable + */ + public function getContactUrlTemplate() + { + return route('contact.index'); + + } + + /** + * @return string + * @throws \Throwable + */ + public function getAskPdfUrlTemplate() + { + return\URL::signedRoute('account.ask-pdf', ['user' => $this->id]); + } + + + + + /** * @return string * @throws \Throwable diff --git a/resources/views/unlayer/button.blade.php b/resources/views/unlayer/button.blade.php index e25d3f6..b628832 100644 --- a/resources/views/unlayer/button.blade.php +++ b/resources/views/unlayer/button.blade.php @@ -8,7 +8,7 @@ {{$slot}} - + -- 2.39.5