Elgg  Version 4.3
save.php
Go to the documentation of this file.
1 <?php
11 
12 /* @var $request \Elgg\Request */
13 
14 $guid = $request->getParam('guid');
15 if (isset($guid)) {
16  $user = get_user($guid);
17 } else {
19 }
20 
21 if (!$user instanceof ElggUser) {
22  throw new EntityNotFoundException();
23 }
24 
25 if (!$user->canEdit()) {
26  throw new EntityPermissionsException();
27 }
28 
29 elgg_make_sticky_form('usersettings', ['password', 'password2']);
30 
32  'user' => $user,
33  'request' => $request,
34 ];
35 
36 // callbacks should return false to indicate that the sticky form should not be cleared
37 if (elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) {
38  elgg_clear_sticky_form('usersettings');
39 }
40 
41 foreach ($request->validation()->all() as $item) {
42  if ($item->isValid()) {
43  if ($message = $item->getMessage()) {
45  }
46  } else {
47  if ($error = $item->getError()) {
49  }
50  }
51 }
52 
53 $data = [
54  'user' => $user,
55  'validation' => $request->validation(),
56 ];
57 
58 return elgg_ok_response($data);
if(!$items) $item
Definition: delete.php:13
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
$request
Definition: livesearch.php:11
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
$guid
Definition: save.php:14
$hooks_params
Definition: save.php:31
$error
Bad request error.
Definition: 400.php:6
elgg_make_sticky_form($form_name, array $ignored_field_names=[])
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:107
Thrown when entity can not be edited or container permissions do not allow it to be written...
$user
Definition: save.php:21
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:380
elgg_register_error_message($options)
Registers a error system message.
Definition: elgglib.php:62
Aggregate action for saving settings.
elgg_ok_response($content= '', $message= '', $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
elgg_register_success_message($options)
Registers a success system message.
Definition: elgglib.php:43
elgg_clear_sticky_form($form_name)
Remove form submission data from the session.
Definition: input.php:123