1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Summernote |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\summernote\controllers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handles incoming requests and outputs data related Summernote module settings |
16
|
|
|
*/ |
17
|
|
|
class Settings extends Controller |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Route page callback to display the module settings page |
22
|
|
|
*/ |
23
|
|
|
public function editSettings() |
24
|
|
|
{ |
25
|
|
|
$this->setTitleEditSettings(); |
26
|
|
|
$this->setBreadcrumbEditSettings(); |
27
|
|
|
$this->setDataModuleSettings(); |
28
|
|
|
$this->submitSettings(); |
29
|
|
|
$this->outputEditSettings(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Sets module settings |
34
|
|
|
*/ |
35
|
|
|
protected function setDataModuleSettings() |
36
|
|
|
{ |
37
|
|
|
$settings = $this->module->getSettings('summernote'); |
38
|
|
|
$settings['selector'] = implode(PHP_EOL, $settings['selector']); |
39
|
|
|
$settings['config'] = gplcart_json_encode($settings['config'], true); |
40
|
|
|
|
41
|
|
|
$this->setData('settings', $settings); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Set title on the module settings page |
46
|
|
|
*/ |
47
|
|
|
protected function setTitleEditSettings() |
48
|
|
|
{ |
49
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Summernote'))); |
50
|
|
|
$this->setTitle($title); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set breadcrumbs on the module settings page |
55
|
|
|
*/ |
56
|
|
|
protected function setBreadcrumbEditSettings() |
57
|
|
|
{ |
58
|
|
|
$breadcrumbs = array(); |
59
|
|
|
|
60
|
|
|
$breadcrumbs[] = array( |
61
|
|
|
'text' => $this->text('Dashboard'), |
62
|
|
|
'url' => $this->url('admin') |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$breadcrumbs[] = array( |
66
|
|
|
'text' => $this->text('Modules'), |
67
|
|
|
'url' => $this->url('admin/module/list') |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Saves the submitted settings |
75
|
|
|
*/ |
76
|
|
|
protected function submitSettings() |
77
|
|
|
{ |
78
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
79
|
|
|
$this->updateSettings(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Validate submitted module settings |
85
|
|
|
*/ |
86
|
|
|
protected function validateSettings() |
87
|
|
|
{ |
88
|
|
|
$this->setSubmitted('settings', null, false); |
89
|
|
|
|
90
|
|
|
$this->validateElement('selector', 'required'); |
91
|
|
|
$this->validateElement('config', 'json_encoded'); |
92
|
|
|
|
93
|
|
|
if ($this->hasErrors()) { |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->setSubmittedArray('selector'); |
98
|
|
|
$this->setSubmitted('config', json_decode($this->getSubmitted('config'), true)); |
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Update module settings |
104
|
|
|
*/ |
105
|
|
|
protected function updateSettings() |
106
|
|
|
{ |
107
|
|
|
$this->controlAccess('module_edit'); |
108
|
|
|
$this->module->setSettings('summernote', $this->getSubmitted()); |
109
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Render and output the module settings page |
114
|
|
|
*/ |
115
|
|
|
protected function outputEditSettings() |
116
|
|
|
{ |
117
|
|
|
$this->output('summernote|settings'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|