-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
79 lines (72 loc) · 3.22 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php namespace LukeTowers\EssentialVars;
use App;
use Lang;
use View;
use Event;
use Config;
use System\Classes\PluginBase;
use Backend\Models\BrandSetting;
/**
* EssentialVars Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*/
public function pluginDetails(): array
{
return [
'name' => 'EssentialVars',
'description' => 'Adds the app_[url|logo|favicon|name|debug|description] variables to Mail & CMS templates',
'author' => 'Luke Towers',
'icon' => 'icon-code',
];
}
/**
* Called when the plugin boots
*/
public function boot(): void
{
App::before(function () {
// Share the variables with the mail template system
Event::listen('mailer.beforeAddContent', function () {
$appVars = [
'url' => url('/'),
'logo' => BrandSetting::getLogo() ?: url('/modules/backend/assets/images/october-logo.svg'),
'favicon' => BrandSetting::getFavicon() ?: url('/modules/backend/assets/images/favicon.png'),
'name' => BrandSetting::get('app_name'),
'tagline' => BrandSetting::get('app_tagline'),
'debug' => Config::get('app.debug', false),
'description' => BrandSetting::get('app_tagline'),
];
View::share('app_url', $appVars['url']);
View::share('app_logo', $appVars['logo']);
View::share('app_favicon', $appVars['favicon']);
View::share('app_name', $appVars['name']);
View::share('app_tagline', $appVars['tagline']);
View::share('app_debug', $appVars['debug']);
View::share('app_description', $appVars['description']);
}, 5);
// Share the variables with the CMS template system
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
$appVars = [
'url' => url('/'),
'logo' => BrandSetting::getLogo() ?: url('/modules/backend/assets/images/october-logo.svg'),
'favicon' => BrandSetting::getFavicon() ?: url('/modules/backend/assets/images/favicon.png'),
'name' => BrandSetting::get('app_name'),
'tagline' => BrandSetting::get('app_tagline'),
'debug' => Config::get('app.debug', false),
'description' => BrandSetting::get('app_tagline'),
];
$controller->vars['app_url'] = $appVars['url'];
$controller->vars['app_logo'] = $appVars['logo'];
$controller->vars['app_favicon'] = $appVars['favicon'];
$controller->vars['app_name'] = $appVars['name'];
$controller->vars['app_tagline'] = $appVars['tagline'];
$controller->vars['app_debug'] = $appVars['debug'];
$controller->vars['app_description'] = $appVars['description'];
});
});
}
}