Elgg  Version 6.1
EntityTrash.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
6 
10 class EntityTrash {
11 
19  public static function registerRestore(\Elgg\Event $event): ?MenuItems {
20  $entity = $event->getEntityParam();
21  if (!$entity->canEdit() || !$entity->hasCapability('restorable') || !$entity->isDeleted()) {
22  return null;
23  }
24 
25  /* @var $return MenuItems */
26  $return = $event->getValue();
27 
28  $container = $entity->getContainerEntity();
29  if ($container instanceof \ElggEntity && !$container->isDeleted()) {
30  $return[] = \ElggMenuItem::factory([
31  'name' => 'restore',
32  'icon' => 'trash-restore-alt',
33  'text' => elgg_echo('restore:this'),
34  'href' => elgg_generate_action_url('entity/restore', [
35  'guid' => $entity->guid,
36  ]),
37  'confirm' => elgg_echo('restoreconfirm'),
38  'priority' => 900,
39  ]);
40  } else {
41  $return[] = \ElggMenuItem::factory([
42  'name' => 'restore_and_move',
43  'icon' => 'trash-restore-alt',
44  'text' => elgg_echo('restore:this:move'),
45  'title' => elgg_echo('restore:this'),
46  'href' => elgg_http_add_url_query_elements('ajax/form/entity/chooserestoredestination', [
47  'entity_guid' => $entity->guid,
48  ]),
49  'link_class' => 'elgg-lightbox',
50  'priority' => 800,
51  ]);
52  }
53 
54  return $return;
55  }
56 }
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
Add items to the entity:trash menu.
Definition: EntityTrash.php:10
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static factory(array $options)
Create an ElggMenuItem from an associative array.
static registerRestore(\Elgg\Event $event)
Register the restore menu item.
Definition: EntityTrash.php:19
$entity
Definition: reset.php:8
$container
Definition: delete.php:23
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:183
A collection of menu items.
Definition: MenuItems.php:10
Models an event passed to event handlers.
Definition: Event.php:11