-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
99 lines (93 loc) · 3.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php namespace Verbant\Livewire;
// use Backend\Classes\NavigationManager;
use Backend\Facades\Backend;
use Enflow\LivewireTwig\LivewireExtension;
use Illuminate\Support\Facades\View;
use System\Classes\PluginBase;
use System\Classes\PluginManager;
use Verbant\Livewire\Classes\ComponentResolver;
use Winter\Storm\Support\Facades\Config;
use Winter\Storm\Support\Facades\Event;
/**
* Livewire Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*/
public function pluginDetails(): array
{
return [
'name' => 'verbant.livewire::lang.plugin.name',
'description' => 'verbant.livewire::lang.plugin.description',
'author' => 'Verbant',
'icon' => 'icon-leaf',
];
}
/**
* Register method, called when the plugin is first registered.
*/
public function register(): void
{
Config::set('livewire_plugin.component_path', storage_path('framework/cache/plugin-components.php'));
}
/**
* Boot method, called right before the request route.
*/
public function boot(): void
{
$pd = collect(PluginManager::instance()->getRegistrationMethodValues('registerLivewireComponents'));
$componentResolver = new ComponentResolver;
$componentResolver->livewireComponents = $pd->reduce(function ($c, $e) {return $c + $e;}, []);
// Event::listen('backend.menu.extendItems', function (NavigationManager $navigationManager) {
// $navigationManager->addSideMenuItems('winter.cms', 'cms', [[
// 'label' => 'Livewire',
// 'url' => 'javascript:;',
// 'icon' => '',
// ]]);
// });
$this->app->bind(\Illuminate\Routing\RouteCollectionInterface::class, \Illuminate\Routing\RouteCollection::class);
View::addExtension('twig', 'twig');
$cacheDir = Config::get('view.compiled');
View::addNamespace('__components', $cacheDir);
$this->app->booted(function() use ($cacheDir) {
$ext = new LivewireExtension;
Event::listen('cms.page.start', function (\Cms\Classes\Controller $controller) use ($ext) {
$twig = $controller->getTwig();
$twig->addExtension($ext);
});
$this->app->extend('twig.environment', function ($twig, $app) use ($cacheDir, $ext) {
$twig->addExtension($ext);
$twig->setCache($cacheDir);
return $twig;
});
});
app('livewire')->resolveMissingComponent([$componentResolver, 'resolve']);
$this->app->instance(ComponentResolver::class, $componentResolver);
}
/**
* Registers backend navigation items for this plugin.
*/
public function registerNavigation(): array
{
return [
'livewire' => [
'label' => 'Livewire',
'url' => Backend::url('verbant/livewire'),
'icon' => 'icon-wrench',
'iconSvg' => 'plugins/winter/builder/assets/images/builder-icon.svg',
'permissions' => [],
'sideMenu' => [
'components' => [
'label' => 'Components',
'icon' => 'icon-database',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'components'],
'permissions' => [],
],
],
],
];
}
}