-
Notifications
You must be signed in to change notification settings - Fork 3
/
SystemSettings.php
62 lines (54 loc) · 1.97 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
<?php
namespace Piwik\Plugins\Signup;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Piwik\Piwik;
/**
* Defines Settings for Signup.
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/**
* @var Setting Whether users signup are allowed or not.
*/
public $allowNewUsersToSignup;
/**
* @var Setting List of email domains allowed to signup from this plugin. If empty, no restriction.
*/
public $allowedEmailDomains;
/**
* Init Signup plugin system settings.
*
* {@InheritDoc}
*/
protected function init()
{
$this->allowNewUsersToSignup = $this->createAllowNewUsersToSignupSetting();
$this->allowedEmailDomains = $this->createAllowedEmailDomainsSetting();
}
private function createAllowNewUsersToSignupSetting()
{
return $this->makeSetting('allowNewUsersToSignup', true, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('Signup_AllowNewUsersToSignup');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('Signup_AllowNewUsersToSignupDescription');
});
}
private function createAllowedEmailDomainsSetting()
{
return $this->makeSetting('allowedEmailDomains', [], FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = Piwik::translate('Signup_AllowedEmailDomains');
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->description = Piwik::translate('Signup_AllowedEmailDomainsDescription');
$field->transform = function ($value) {
if (empty($value)) {
return [];
}
$domains = array_map('trim', $value);
$domains = array_filter($domains, 'strlen');
$domains = array_values($domains);
return $domains;
};
});
}
}