-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
88 lines (73 loc) · 2.95 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
<?php namespace SunLab\UnsplashForBlog;
use Backend;
use Illuminate\Support\Facades\Event;
use System\Classes\PluginBase;
use System\Classes\PluginManager;
class Plugin extends PluginBase
{
public $require = ['SunLab.UnsplashPicker'];
public function pluginDetails()
{
return [
'name' => 'UnsplashForBlog',
'description' => 'sunlab.unsplashforblog::lang.plugin.description',
'author' => 'SunLab',
'icon' => 'icon-leaf'
];
}
public function boot()
{
if (\SunLab\UnsplashPicker\Models\Settings::instance()->isConfigured()) {
$pluginManager = PluginManager::instance();
if ($pluginManager->hasPlugin('RainLab\Blog') || $pluginManager->hasPlugin('Winter\Blog')) {
$this->applyOnRainLabBlog();
}
if ($pluginManager->hasPlugin('Lovata\GoodNews')) {
$this->applyOnLovataGoodNews();
}
}
}
protected function applyOnRainLabBlog()
{
Event::listen('backend.form.extendFields', static function (Backend\Widgets\Form $widget) {
if (
(!$widget->getController() instanceof \RainLab\Blog\Controllers\Posts ||
!$widget->model instanceof \RainLab\Blog\Models\Post) &&
(!$widget->getController() instanceof \Winter\Blog\Controllers\Posts ||
!$widget->model instanceof \Winter\Blog\Models\Post)
) {
return;
}
$fileuploadField = $widget->getField('featured_images');
$fileuploadField->config['type'] = 'unsplashpicker';
$widget->removeField('featured_images');
$widget->addSecondaryTabFields([
'featured_images' => $fileuploadField->config
]);
});
}
protected function applyOnLovataGoodNews()
{
Event::listen('backend.form.extendFields', static function (Backend\Widgets\Form $widget) {
if ((
!$widget->getController() instanceof \Lovata\GoodNews\Controllers\Articles ||
!$widget->model instanceof \Lovata\GoodNews\Models\Article
) && (
!$widget->getController() instanceof \Lovata\GoodNews\Controllers\Categories ||
!$widget->model instanceof \Lovata\GoodNews\Models\Category
)) {
return;
}
$previewImageField = $widget->getField('preview_image');
$previewImageField->config['type'] = 'unsplashpicker';
$imagesField = $widget->getField('images');
$imagesField->config['type'] = $previewImageField->config['type'] = 'unsplashpicker';
$widget->removeField('preview_image');
$widget->removeField('images');
$widget->addTabFields([
'preview_image' => $previewImageField->config,
'images' => $imagesField->config
]);
});
}
}