-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugin.php
100 lines (92 loc) · 3.16 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
100
<?php namespace PKleindienst\BlogSeries;
use Backend;
use Event;
use System\Classes\PluginBase;
use RainLab\Blog\Controllers\Posts as PostsController;
use RainLab\Blog\Models\Post as PostModel;
/**
* BlogSeries Plugin Information File
* @package PKleindienst\BlogSeries
*/
class Plugin extends PluginBase
{
/**
* @var array Require the RainLab.Blog plugin
*/
public $require = ['RainLab.Blog'];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'BlogSeries',
'description' => 'Add posts to series',
'author' => 'PKleindienst',
'icon' => 'icon-list-alt',
'homepage' => 'https://github.com/PascalKleindienst/october-blogseries-extension'
];
}
/**
* @return array
*/
public function registerComponents()
{
return [
'PKleindienst\BlogSeries\Components\BlogSeries' => 'blogSeries',
'PKleindienst\BlogSeries\Components\BlogSeriesList' => 'blogSeriesList',
'PKleindienst\BlogSeries\Components\PostNavigation' => 'postNavigation',
'PKleindienst\BlogSeries\Components\RelatedSeries' => 'relatedSeries'
];
}
/**
* Inject into Blog Posts
*/
public function boot()
{
// Extend the model
PostModel::extend(function ($model) {
$model->belongsTo['series'] = [
'PKleindienst\BlogSeries\Models\Series'
];
});
// Extend the navigation
Event::listen('backend.menu.extendItems', function ($manager) {
$manager->addSideMenuItems('RainLab.Blog', 'blog', [
'series' => [
'label' => 'Series',
'icon' => 'icon-list-alt',
'code' => 'series',
'owner' => 'RainLab.Blog',
'permissions' => ['rainlab.blog.access_posts'],
'url' => Backend::url('pkleindienst/blogseries/series')
]
]);
});
// Extend the controller
PostsController::extendFormFields(function ($form, $model) {
if (!$model instanceof PostModel) {
return;
}
$form->addSecondaryTabFields([
'categories' => [
'tab' => 'rainlab.blog::lang.post.tab_categories',
'type' => 'relation',
'commentAbove' => 'rainlab.blog::lang.post.categories_comment',
'placeholder' => 'rainlab.blog::lang.post.categories_placeholder',
'span' => 'left'
],
'series' => [
'label' => 'Series',
'tab' => 'rainlab.blog::lang.post.tab_categories',
'type' => 'relation',
'nameFrom' => 'title',
'span' => 'right',
'emptyOption' => '-- None --'
]
]);
});
}
}