Elgg  Version 6.0
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_event_results('usersettings:save', 'user', $event_params, true)) {
38  elgg_clear_sticky_form('usersettings');
39 }
40 
41 foreach ($request->validation()->all() as $item) {
42  if ($item->isValid()) {
43  $message = $item->getMessage();
44  if (!elgg_is_empty($message)) {
46  }
47  } else {
48  $error = $item->getError();
49  if (!elgg_is_empty($error)) {
51  }
52  }
53 }
54 
55 return elgg_ok_response([
56  'user' => $user,
57  'validation' => $request->validation(),
58 ]);
if(!$items) $item
Definition: delete.php:13
$event_params
Definition: save.php:31
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_register_success_message(string|array $options)
Registers a success system message.
Definition: elgglib.php:43
$request
Definition: livesearch.php:12
elgg_clear_sticky_form(string $form_name)
Remove form submission data from the session.
Definition: input.php:121
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
$guid
Definition: save.php:14
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
$error
Bad request error.
Definition: 400.php:6
Thrown when entity can not be edited or container permissions do not allow it to be written...
$user
Definition: save.php:21
elgg_make_sticky_form(string $form_name, array $ignored_field_names=[])
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:105
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_register_error_message(string|array $options)
Registers a error system message.
Definition: elgglib.php:62
Aggregate action for saving settings.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24