|
1
|
|
|
<?php |
|
2
|
|
|
namespace UserManagement\Forms; |
|
3
|
|
|
|
|
4
|
|
|
use SilverStripe\Forms\FieldList; |
|
5
|
|
|
use SilverStripe\Forms\Form; |
|
6
|
|
|
use SilverStripe\Forms\ReadOnlyField; |
|
7
|
|
|
use SilverStripe\Forms\FormAction; |
|
8
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
9
|
|
|
use SilverStripe\Security\Security; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ProfileForm |
|
13
|
|
|
* |
|
14
|
|
|
* @package user-management |
|
15
|
|
|
*/ |
|
16
|
|
|
class ProfileForm extends SignUpForm |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
protected $siteConfig; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct($controller, $name) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setAttribute('id', 'ProfileForm'); |
|
24
|
|
|
$this->setsiteConfig(); |
|
25
|
|
|
parent::__construct($controller, $name, $this->getFormFields($controller), $this->getFormActions()); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
protected function getFormFields($controller = null) |
|
28
|
|
|
{ |
|
29
|
|
|
$member = Security::getCurrentUser(); |
|
30
|
|
|
$fieldList = parent::getFormFields(); |
|
31
|
|
|
$fieldList->removeByName('Password'); |
|
32
|
|
|
$fieldList->removeByName('Email'); |
|
33
|
|
|
$this->setAttribute('id', 'ProfileForm'); |
|
34
|
|
|
$fieldList->insertBefore(ReadOnlyField::create("Email", "Email", $member->Email), 'Mobile'); |
|
|
|
|
|
|
35
|
|
|
return $fieldList; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return FieldList Actions for this form. |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function getFormActions() |
|
42
|
|
|
{ |
|
43
|
|
|
return FieldList::create( |
|
44
|
|
|
FormAction::create("doSubmitProfile", "Submit") |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Form action, updates the user profile. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function doSubmitProfile($data, Form $form) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$member = Security::getCurrentUser(); |
|
54
|
|
|
if ($member) { |
|
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
$form->saveInto($member); |
|
57
|
|
|
$member->write(); |
|
58
|
|
|
$msg = $this->getCustomMessage('ProfileUpdateSuccess')!="" |
|
59
|
|
|
? $this->getCustomMessage('ProfileUpdateSuccess') : "Profile updated!"; |
|
60
|
|
|
$form->sessionMessage($msg, 'good'); |
|
61
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
62
|
|
|
$msg = $this->getCustomMessage('ProfileUpdatError')!="" |
|
63
|
|
|
? $this->getCustomMessage('ProfileUpdatError') : "Technical issue, Profile not updated!"; |
|
64
|
|
|
$form->sessionMessage($msg, 'bad'); |
|
65
|
|
|
} |
|
66
|
|
|
} else { |
|
67
|
|
|
return $this->controller->redirect($this->siteConfig->LoginUrl()->URLSegment); |
|
68
|
|
|
} |
|
69
|
|
|
return $this->controller->redirectBack(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
public function getCustomMessage($field) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->siteConfig->$field; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function setsiteConfig() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->siteConfig = SiteConfig::current_site_config(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.