Elgg  Version master
restore.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('guid');
8  return get_entity($guid);
9 });
10 if (!$entity instanceof \ElggEntity || !$entity->isDeleted()) {
11  return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
12 }
13 
14 if (!$entity->canEdit()) {
15  return elgg_error_response(elgg_echo('entity:restore:permission_denied'));
16 }
17 
18 // determine what name to show on success
19 $display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');
20 
21 if (!$entity->restore()) {
22  return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
23 }
24 
26  "entity:restore:{$entity->type}:{$entity->subtype}:success",
27  "entity:restore:{$entity->type}:success",
28  'entity:restore:success',
29 ];
30 
31 $message = '';
32 if (get_input('show_success', true)) {
33  foreach ($success_keys as $success_key) {
34  if (elgg_language_key_exists($success_key)) {
35  $message = elgg_echo($success_key, [$display_name]);
36  break;
37  }
38  }
39 }
40 
41 return elgg_ok_response('', $message);
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:304
if(!$entity->restore()) $success_keys
Definition: restore.php:25
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_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$guid
Default entity restore action.
Definition: restore.php:6
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
$entity
Definition: restore.php:7
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:123
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
const ELGG_SHOW_DELETED_ENTITIES
Definition: constants.php:127
$message
Definition: restore.php:31
if(!$entity instanceof\ElggEntity||!$entity->isDeleted()) if(!$entity->canEdit()) $display_name
Definition: restore.php:19