]> _ Git - psq.git/commitdiff
unlayer buttons
authorLouis Jeckel <louis.jeckel@outlook.com>
Tue, 17 Nov 2020 16:10:33 +0000 (17:10 +0100)
committerLouis Jeckel <louis.jeckel@outlook.com>
Tue, 17 Nov 2020 16:10:33 +0000 (17:10 +0100)
app/EmailTemplate.php
app/Nova/EmailTemplate.php
app/TemplateVariables.php
resources/views/unlayer/button.blade.php

index 2a3b5f8add0568461c0c2da8b26b246eb20e4b77..78b238aa61a82f861e176fc4fa16fc0705102035 100644 (file)
@@ -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)
     {
index daf9d56f55ed6e2fdd33946ba821c095046b7428..5e88b50a5d276eeaf7865c8f47a887ceb32ed2d5 100644 (file)
@@ -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([
index ba7e74fec47cd5c20c373ef42068d7586de0609e..4689b70c8abe97fcf50e9f8fffa65041f10d40aa 100644 (file)
@@ -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
index e25d3f658553b7be6b047107a202ea8f57e6ab49..b6288326508ced978b1efc1c4b753ae2ae7c4536 100644 (file)
@@ -8,7 +8,7 @@
     <a href="{!! $url !!}" target="_blank" class="v-size-width" style="box-sizing: border-box;display: inline-block;font-family:'Open Sans',sans-serif;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;">
       <span class="v-padding" style="display:block;padding:10px 20px;line-height:120%;"><span style="font-size: 14px; line-height: 16.8px;">{{$slot}}</span></span>
     </a>
-  <!--[if mso]></center></td></tr></table><![endif]-->
+  <!--[if mso]></center></v:roundrect></td></tr></table><![endif]-->
 </div>
 
       </td>