-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmymodule.php
142 lines (117 loc) · 4.18 KB
/
mymodule.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
<?php
/*
* @author d@rkWolf <darkWolf.PR@seznam.cz>
* @copyright 2016 d@rkWolf
*/
if (!defined('_PS_VERSION_'))
exit;
class MyModule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'others';
$this->version = '1.0.0';
$this->author = 'd@rkWolf';
$this->need_instance = 0;
$this->ps_version_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('My module');
$this->description = $this->l('description');
$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 (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!parent::install() ||
!Configuration::updateValue('MYMODULE_NAME', 'test value')
) {
return false;
}
return true;
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::deleteByName('MYMODULE_NAME')
) {
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_LAND_DEFAULT');
//Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Configuration value'),
'name' => 'MYMODULE_NAME',
'size' => 20,
'required' => true
)
),
'submit' => array(
'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 top of the screen
$helper->submit_action = 'submit' . $this->name;
$helper->toolbar_btn = array(
'save' => array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name.
'&token=' . Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list'),
)
);
//Load current value
$helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');
return $helper->generateForm($fields_form);
}
}