-
Notifications
You must be signed in to change notification settings - Fork 4
/
SystemSettings.php
65 lines (58 loc) · 2.12 KB
/
SystemSettings.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 Piwik\Plugins\RerIntranetSubnetwork;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Psr\Log\LoggerInterface;
/**
* Defines Settings for RerIntranetSubnetwork.
*
* Usage like this:
* $settings = new SystemSettings();
* $settings->subnetwork_regex->getValue();
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $subnetwork_regex;
/** @var Setting */
public $subnetwork_default;
protected function init()
{
$this->subnetwork_default = $this->createSubnetworkDefaultSetting();
$this->subnetwork_regex = $this->createSubnetworkRegexSetting();
}
private function createSubnetworkDefaultSetting()
{
return $this->makeSetting(
'subnetwork_default',
true,
FieldConfig::TYPE_BOOL,
function (FieldConfig $field) {
$field->title = Piwik::translate('RerIntranetSubnetwork_SettingDefaultTitle');
$field->description = Piwik::translate('RerIntranetSubnetwork_SettingDefaultDescription');
$field->availableValues = [ true, false ];
}
);
}
private function createSubnetworkRegexSetting()
{
return $this->makeSetting(
'subnetwork_regex',
null,
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = Piwik::translate('RerIntranetSubnetwork_SettingTitle');
$field->description = Piwik::translate('RerIntranetSubnetwork_SettingDescription');
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
// $field->validate = function ($value, Setting $field) {
// if ( '^' !== substr($value, 0, 2) || '/' !== substr($value, -1) )
// {
// throw new \Exception(Piwik::translate('RerIntranetSubnetwork_SettingException'));
// }
// };
}
);
}
}