forked from glenn-de-backer/blogfeaturedvideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
65 lines (53 loc) · 1.83 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
<?php namespace Simplicitylab\BlogFeaturedVideo;
use Event;
use System\Classes\PluginBase;
use Rainlab\Blog\Controllers\Posts as PostsController;
use RainLab\Blog\Models\Post as PostModel;
use Simplicitylab\BlogFeaturedVideo\Models\FeaturedVideo;
/**
* BlogFeaturedVideo Plugin Information File
*/
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' => 'BlogFeaturedVideo',
'description' => 'No description provided yet...',
'author' => 'Simplicitylab',
'icon' => 'icon-leaf'
];
}
public function boot()
{
// extend post model
PostModel::extend(function($model) {
// add a hasone relationship with the featuredvideo model
$model->hasOne['featuredvideo'] = ['Simplicitylab\BlogFeaturedVideo\Models\FeaturedVideo'];
});
// extend form fields
PostsController::extendFormFields(function($widget, $model, $context) {
if ($context != 'update') return;
if (!FeaturedVideo::getFromPost($model)) return;
// add featured video textarea
$widget->addFields([
'featuredvideo[iframe_content]' => [
'label' => 'simplicitylab.blogfeaturedvideo::lang.backend.featuredvideo',
'tab' => 'rainlab.blog::lang.post.tab_manage',
'type' => 'textarea',
'size' => 'small',
'comment' => 'simplicitylab.blogfeaturedvideo::lang.backend.description'
]
], 'secondary');
});
}
}