-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugin.php
53 lines (45 loc) · 1.52 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
<?php namespace Isswp101\PageSettings;
use Cms\Classes\Page;
use Illuminate\Support\Facades\Event;
use Isswp101\PageSettings\Classes\PageSettingsFacade;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'Page Settings',
'description' => 'Plugin allows you to store page settings in the database.',
'author' => 'Isswp101',
];
}
public function boot()
{
$this->registerPageEvents();
}
protected function registerPageEvents()
{
$pageSettings = new PageSettingsFacade();
// Frontend
Event::listen('cms.page.beforeRenderPage', function ($c, $page) use ($pageSettings) {
$pageSettings->fillPage($page);
});
// Backend
Event::listen('cms.template.processSettingsAfterLoad', function ($c, $template) use ($pageSettings) {
if ($template instanceof Page) {
$pageSettings->fillPage($template);
}
});
// Backend
Event::listen('cms.template.save', function ($c, $template) use ($pageSettings) {
if ($template instanceof Page) {
$pageSettings->save($template);
}
});
Event::listen('cms.template.processSettingsAfterLoad', function ($c, $template) use ($pageSettings) {
if ($template instanceof Page) {
$pageSettings->setOriginalFileName($template->getFileName());
}
});
}
}