-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
103 lines (90 loc) · 3.18 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
101
102
103
<?php namespace Inetis\InputCounter;
use App;
use Backend\FormWidgets\RichEditor;
use Backend\Widgets\Form;
use Event;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'Input Counter',
'description' => 'Add counters to text input',
'author' => 'inetis',
'icon' => 'icon-image'
];
}
public function boot()
{
// Check if we are currently in backend
if (!App::runningInBackend()) {
return;
}
// Listen for `backend.page.beforeDisplay` event and inject js to current controller instance.
Event::listen('backend.page.beforeDisplay', function ($controller, $action, $params) {
$controller->addCss("/plugins/inetis/inputcounter/assets/css/style.css");
$controller->addJs("/plugins/inetis/inputcounter/assets/js/main.js");
});
RichEditor::extend(function ($controller) {
$controller->addJs("/plugins/inetis/inputcounter/assets/js/froala-plugin.js");
});
$this->registerCmsSeoRecommendation();
$this->registerStaticPagesSeoRecommendation();
}
private function registerStaticPagesSeoRecommendation()
{
if (!class_exists(\RainLab\Pages\Classes\Page::class)) {
return;
}
Event::listen('backend.form.extendFieldsBefore', function (Form $form) {
if (
!$form->getController() instanceof \RainLab\Pages\Controllers\Index ||
!$form->model instanceof \RainLab\Pages\Classes\Page ||
$form->isNested
) {
return;
}
$form->tabs['fields']['viewBag[meta_title]'] += [
'attributes' => [
'data-counter',
'data-optimal-min-length' => 50,
'data-optimal-max-length' => 60,
]
];
$form->tabs['fields']['viewBag[meta_description]'] += [
'attributes' => [
'data-counter',
'data-optimal-min-length' => 50,
'data-optimal-max-length' => 300,
]
];
});
}
private function registerCmsSeoRecommendation()
{
Event::listen('backend.form.extendFieldsBefore', function (Form $form) {
if (
!$form->getController() instanceof \Cms\Controllers\Index ||
!$form->model instanceof \Cms\Classes\Page ||
$form->isNested
) {
return;
}
$form->tabs['fields']['settings[meta_title]'] += [
'attributes' => [
'data-counter',
'data-optimal-min-length' => 50,
'data-optimal-max-length' => 60,
]
];
$form->tabs['fields']['settings[meta_description]'] += [
'attributes' => [
'data-counter',
'data-optimal-min-length' => 50,
'data-optimal-max-length' => 300,
]
];
});
}
}