|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class SlackSignupForm extends Form |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
private $siteConfig; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* SlackSignupForm constructor. |
|
10
|
|
|
* @param Controller $controller |
|
11
|
|
|
* @param string $name |
|
12
|
|
|
* @param FieldList $fields |
|
13
|
|
|
* @param FieldList $actions |
|
14
|
|
|
* @param null $validator |
|
|
|
|
|
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct( |
|
17
|
|
|
Controller $controller = null, |
|
|
|
|
|
|
18
|
|
|
$name, |
|
19
|
|
|
FieldList $fields = null, |
|
|
|
|
|
|
20
|
|
|
FieldList $actions = null, |
|
21
|
|
|
$validator = null |
|
22
|
|
|
) { |
|
23
|
|
|
$this->siteConfig = SiteConfig::current_site_config(); |
|
|
|
|
|
|
24
|
|
|
if (!$controller) { |
|
25
|
|
|
$controller = Controller::curr(); |
|
26
|
|
|
} |
|
27
|
|
|
if (!$fields) { |
|
28
|
|
|
$fields = $this->getFormFields(); |
|
29
|
|
|
} |
|
30
|
|
|
if (!$actions) { |
|
31
|
|
|
$actions = $this->getFormActions(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return FieldList |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getFormFields() |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$this->siteConfig->SlackToken) { |
|
43
|
|
|
return FieldList::create([ |
|
44
|
|
|
LiteralField::create( |
|
|
|
|
|
|
45
|
|
|
'Setup', |
|
46
|
|
|
_t('SlackSignupForm.Setup', 'StripeSlack has not yet been configured correctly') |
|
|
|
|
|
|
47
|
|
|
) |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
$fields = FieldList::create( |
|
51
|
|
|
[ |
|
52
|
|
|
LiteralField::create( |
|
53
|
|
|
'Intro', |
|
54
|
|
|
_t('SlackSignupForm.Intro', 'Fill out the form below to request access to Slack') |
|
55
|
|
|
), |
|
56
|
|
|
TextField::create('Name', _t('SlackSignupForm.Name', 'My name is')), |
|
|
|
|
|
|
57
|
|
|
EmailField::create('Email', _t('SlackSignupForm.Email', 'My email address is')) |
|
|
|
|
|
|
58
|
|
|
->setAttribute('required', true), |
|
59
|
|
|
] |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$this->extend('updateFormFields', $fields); |
|
63
|
|
|
|
|
64
|
|
|
return $fields; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return FieldList |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function getFormActions() |
|
71
|
|
|
{ |
|
72
|
|
|
if (!$this->siteConfig->SlackToken) { |
|
73
|
|
|
return FieldList::create(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return FieldList::create([ |
|
77
|
|
|
FormAction::create('submitSlackForm', _t('SlackSignupForm.Submit', 'Submit')) |
|
|
|
|
|
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param array $data |
|
83
|
|
|
* @param SlackSignupForm $form |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function submitSlackForm($data, $form) |
|
86
|
|
|
{ |
|
87
|
|
|
$signup = SlackInvite::create(); |
|
88
|
|
|
$form->saveInto($signup); |
|
89
|
|
|
$userID = $signup->write(); |
|
90
|
|
|
/** @var SlackInvite $signup We need to re-fetch from the database after writing */ |
|
91
|
|
|
$signup = SlackInvite::get()->byID($userID); |
|
92
|
|
|
$this->redirectSlack($signup->Invited); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* This method seems long, but it's primarily switching between CMS and normal user |
|
97
|
|
|
* Plus a check if the URL's are set on the config. |
|
98
|
|
|
* |
|
99
|
|
|
* @param boolean $success |
|
100
|
|
|
* @return bool|SS_HTTPResponse |
|
|
|
|
|
|
101
|
|
|
*/ |
|
102
|
|
|
public function redirectSlack($success) |
|
103
|
|
|
{ |
|
104
|
|
|
$config = SiteConfig::current_site_config(); |
|
105
|
|
|
if (!$success) { |
|
106
|
|
|
if ($config->SlackErrorBackURLID) { |
|
107
|
|
|
return $this->controller->redirect($config->SlackErrorBackURL()->Link()); |
|
108
|
|
|
} |
|
109
|
|
|
$this->controller->redirect($this->controller->Link('error')); |
|
110
|
|
|
} |
|
111
|
|
|
if ($config->SlackBackURLID) { |
|
112
|
|
|
return $this->controller->redirect($config->SlackBackURL()->Link()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return $this->controller->redirect($this->controller->Link('success')); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths