<excludeFolder url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<excludeFolder url="file://$MODULE_DIR$/vendor/html2text/html2text" />
<excludeFolder url="file://$MODULE_DIR$/vendor/http-interop/http-factory-guzzle" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/idf/nova-unlayer-field" />
<excludeFolder url="file://$MODULE_DIR$/vendor/itsgoingd/clockwork" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jean85/pretty-package-versions" />
<excludeFolder url="file://$MODULE_DIR$/vendor/judev/php-htmltruncator" />
<path value="$PROJECT_DIR$/vendor/psq/psq-theme" />
<path value="$PROJECT_DIR$/vendor/numaxlab/nova-ckeditor5-classic" />
<path value="$PROJECT_DIR$/vendor/metrixinfo/nova-iframe" />
+ <path value="$PROJECT_DIR$/vendor/idf/nova-unlayer-field" />
</include_path>
</component>
<component name="PhpInterpreters">
namespace App;
use App\Mail\TemplateMail;
+use App\Mail\TemplateMailOld;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Mail\Mailable;
use Illuminate\Support\Str;
/**
public $timestamps = false;
protected $casts = [
- 'show_in_actions' => 'boolean'
+ 'show_in_actions' => 'boolean',
+ 'design' => 'array',
];
+ protected $guarded = [];
+
/**
* @param $slug
* @return EmailTemplate
$match = Str::before(Str::after($matches[0], '%'), '%');
- return $user->templateAttribute($match);
+ return $user->templateAttribute($match, null) ?? $matches[0];
}, $content);
public function render()
{
$user = User::query()->offset(1)->first();
- return (new TemplateMail($this->fillFor($user), $this->fillSubjectFor($user)))->render();
+ return $this->getMailFor($user)->render();
+ }
+
+ /**
+ * @param User $user
+ * @return Mailable
+ */
+ public function getMailableFor(User $user)
+ {
+ return $this->html ?
+ (new TemplateMail($this->fillFor($user), $this->fillSubjectFor($user))) :
+ (new TemplateMailOld($this->fillFor($user), $this->fillSubjectFor($user)));
}
/**
{
return $this->render();
}
+
+ public function getContentAttribute()
+ {
+ return $this->html ?? $this->getAttributes()['content'];
+ }
+
+
}
*/
public function build()
{
- return $this->markdown('emails.template');
+ return $this->html($this->content);
}
+
+
}
--- /dev/null
+<?php
+
+namespace App\Mail;
+
+use App\EmailTemplate;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class TemplateMailOld
+ * @package App\Mail
+ * @deprecated
+ * @todo REMOVE
+ */
+class TemplateMailOld extends Mailable implements ShouldQueue
+{
+ use Queueable, SerializesModels;
+
+ /**
+ * @var string
+ */
+ public $content;
+
+
+ /**
+ * Create a new message instance.
+ *
+ * @param $content
+ * @param $subject
+ */
+ public function __construct($content, $subject)
+ {
+ $this->content = $content;
+ $this->subject = $subject;
+ $this->replyTo(config('app.emails.olivier'));
+ }
+
+ /**
+ * Build the message.
+ *
+ * @return $this
+ */
+ public function build()
+ {
+ return $this->markdown('emails.template');
+ }
+
+
+}
/**
* @return array
+ * @todo
*/
public static function getActions()
{
+ return [];
return \App\EmailTemplate::inActionsMenu()->get()->mapInto(self::class)->toArray();
}
}
namespace App\Nova;
+use IDF\NovaUnlayerField\Unlayer;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
Text::make('Nom code', 'slug')->hideFromIndex(),
Text::make('Nom', 'name')->required(),
Text::make('Sujet', 'subject'),
- Trix::make('Contenu', 'content')->alwaysShow()->required(),
Boolean::make('Dans menu action ?', 'show_in_actions'),
Iframe::make('Aperçu', 'renderedHtml'),
+ Unlayer::make('Email', 'design')->config([
+ 'projectId' => config('services.unlayer.projectId'),
+ 'templateId' => $this->design === null ? 20390 : null,
+ 'locale' => app()->getLocale(),
+ 'specialLinks' => [
+ [
+ 'name' => 'Home',
+ 'href' => route('home'),
+ ],
+ [
+ 'name' => 'Contact',
+ 'href' => route('contact.index')
+ ],
+
+ ],
+ ])->savingCallback(function ($request, $attribute, $model, $html)
+ {
+ $model->update([
+ 'design' => $request->get('design'),
+ 'html' => $request->get('design_html')
+ ]);
+ })->hideFromDetail(),
];
}
$template = EmailTemplate::findSlug($template);
}
- \Mail::to($this)->send(new TemplateMail(
- $template->fillFor($this),
- $template->fillSubjectFor($this)
- ));
+
+ \Mail::to($this)->send($template->getMailableFor($this));
}
/**
* @param $subject
* @param $content
+ * @todo Broken
* Fills subject and content, then sends mail
*/
public function sendTemplateEmail($subject, $content)
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"html2text/html2text": "^4.3",
+ "idf/nova-unlayer-field": "^0.2.1",
"itsgoingd/clockwork": "^4.1",
"judev/php-htmltruncator": "^1.2",
"kriswallsmith/buzz": "^1.1",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "170a4b87161eb1a26074692e0e8292bd",
+ "content-hash": "28f3513135fec03d3b77372b1e83ad1f",
"packages": [
{
"name": "algolia/algoliasearch-client-php",
],
"time": "2018-07-31T19:32:56+00:00"
},
+ {
+ "name": "idf/nova-unlayer-field",
+ "version": "0.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/InteractionDesignFoundation/nova-unlayer-field.git",
+ "reference": "10fb6a76a075c699f38ae8d16786d161f408d0b8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/InteractionDesignFoundation/nova-unlayer-field/zipball/10fb6a76a075c699f38ae8d16786d161f408d0b8",
+ "reference": "10fb6a76a075c699f38ae8d16786d161f408d0b8",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1.0"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "IDF\\NovaUnlayerField\\ServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "IDF\\NovaUnlayerField\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "A Laravel Nova field for Unlayer to compose emails and landing pages",
+ "keywords": [
+ "laravel",
+ "nova"
+ ],
+ "time": "2020-04-23T11:09:48+00:00"
+ },
{
"name": "imgix/imgix-php",
"version": "3.3.0",
],
+
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
'stripe' => [
'enable' => env('STRIPE_ENABLE', false),
'test_social_id' => env('STRIPE_TEST_SOCIAL_ID', null)
+ ],
+
+ 'unlayer' => [
+ 'projectId' => 7628,
]
];
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddDesignToEmailTemplates extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('email_templates', function (Blueprint $table) {
+ $table->json('design')->nullable();
+ $table->longText('html')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('email_templates', function (Blueprint $table) {
+ $table->dropColumn('design');
+ $table->dropColumn('html');
+ });
+ }
+}