-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
78 lines (71 loc) · 2.91 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
<?php namespace MG\PageBuilder;
use System\Classes\PluginBase;
use App;
use Event;
use Cms\Classes\Theme;
use RainLab\Pages\Classes\Menu as PagesMenu;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'mg.pagebuilder::lang.plugin.name',
'description' => 'mg.pagebuilder::lang.plugin.description',
'author' => 'Matthew Guillot',
'icon' => 'icon-files-o'
];
}
public function boot()
{
// Check if we are currently in backend module.
if (!App::runningInBackend()) {
return;
}
//Add Builder button to RainLab/Pages plugin toolbar
Event::listen('backend.form.extendFields', function ($widget, $fields) {
$controller = $widget->getController();
if ($controller instanceof \RainLab\Pages\Controllers\Index && $widget->model instanceof \RainLab\Pages\Classes\Page) {
$controller->addJs('/plugins/mg/pagebuilder/assets/js/october/toolbarbtn.js');
!empty($fields['toolbar']) && $fields['toolbar']->path = 'plugins/mg/pagebuilder/controllers/index/page_toolbar';
$widget->addTabFields([
'viewBag[banner_image]' => [
'tab' => 'mg.pagebuilder::lang.page.banner_tab',
'label' => 'mg.pagebuilder::lang.page.banner_image',
'field' => 'viewBag[banner_image]',
'span' => 'auto',
'type' => 'mediafinder',
'mode' => 'image',
'comment' => 'Banner Image at the top of the page'
],
'viewBag[banner_title]' => [
'tab' => 'mg.pagebuilder::lang.page.banner_tab',
'label' => 'mg.pagebuilder::lang.page.banner_title',
'field' => 'viewBag[banner_title]',
'span' => 'auto',
'type' => 'text'
],
'viewBag[page_navigation]' => [
'tab' => 'mg.pagebuilder::lang.page.banner_tab',
'label' => 'mg.pagebuilder::lang.page.secondary_nav',
'options' => $this->getMenuCodeOptions(),
'showSearch' => true,
'span' => 'auto',
'required' => 1,
'type' => 'dropdown',
'placeholder' => '- No Menu Selected -'
],
]);
}
});
}
private function getMenuCodeOptions()
{
$result = [];
$theme = Theme::getEditTheme();
$menus = PagesMenu::listInTheme($theme, true);
foreach ($menus as $menu) {
$result[$menu->code] = $menu->name;
}
return $result;
}
}