-
Notifications
You must be signed in to change notification settings - Fork 0
/
basemodule.php
executable file
·148 lines (115 loc) · 4.09 KB
/
basemodule.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class BaseModule extends Module
{
public function __construct()
{
$this->name = 'baseModule';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Kusflo';
$this->need_instance = 0;
$this->ps_versions_compliancy = [
'min' => '1.6',
'max' => _PS_VERSION_
];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My Base Module');
$this->description = $this->l('My Base module in prestashop.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('MYMODULE_NAME')) {
$this->warning = $this->l('No name provided');
}
}
public function install()
{
if(!Configuration::updateValue('MYMODULE_NAME', 'Base Module') ||
!parent::install()
){
return false;
}
return true;
}
public function uninstall()
{
if(!Configuration::deleteByName('MYMODULE_NAME') ||
!parent::uninstall()
) {
return false;
}
return true;
}
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit'.$this->name)) {
$myModuleName = strval(Tools::getValue('MYMODULE_NAME'));
if (
!$myModuleName ||
empty($myModuleName) ||
!Validate::isGenericName($myModuleName)
) {
$output .= $this->displayError($this->l('Invalid Configuration value'));
} else {
Configuration::updateValue('MYMODULE_NAME', $myModuleName);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
return $output.$this->displayForm();
}
public function displayForm()
{
// Get default language
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init Fields form array
$fieldsForm[0]['form'] = [
'legend' => [
'title' => $this->l('Settings'),
],
'input' => [
[
'type' => 'text',
'label' => $this->l('Configuration value'),
'name' => 'MYMODULE_NAME',
'size' => 20,
'required' => true
]
],
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
]
];
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $defaultLang;
$helper->allow_employee_form_lang = $defaultLang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = [
'save' => [
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
],
'back' => [
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
]
];
// Load current value
$helper->fields_value['MYMODULE_NAME'] = Tools::getValue('MYMODULE_NAME', Configuration::get('MYMODULE_NAME'));
return $helper->generateForm($fieldsForm);
}
}